From patchwork Fri Oct 12 10:16:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638395 X-Patchwork-Delegate: kvalo@adurom.com 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 3F4B314E2 for ; Fri, 12 Oct 2018 10:16:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EB2E28066 for ; Fri, 12 Oct 2018 10:16:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22C292B8FD; Fri, 12 Oct 2018 10:16:47 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B4E228066 for ; Fri, 12 Oct 2018 10:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728423AbeJLRs0 (ORCPT ); Fri, 12 Oct 2018 13:48:26 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37176 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728409AbeJLRsZ (ORCPT ); Fri, 12 Oct 2018 13:48:25 -0400 Received: by mail-wr1-f65.google.com with SMTP id y11-v6so12804872wrd.4 for ; Fri, 12 Oct 2018 03:16:43 -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=b5WwaW4si7bw34Y7AH9984pXepEksr2eQHK2C8Ct4Hs=; b=QTTnBIbi6A5NU/EVpd1C+bzFnS2jP68T718G738GAPgXxS9fMuxhbkHKF4wm2ZkEzt 6uwZ6B1Ap2cExaQQTdjhrG8k+RGYcx4ngPgDNgV01vdaG6KFAIuE7KFjnXqY7KzJ4z8i Ea1DHrdhSr2eLeyA0yUO3RKkoqI7DlEI2XGw32WeQdbVKE4FG/nonWmJKnKyWd2AGw4i WJs5nXp3Q5a8zXoNaci5CA8OaHEczFADNBQQuOebVT6o2Fvj8LZEMH6fYohHz1JDaDSJ rFpSl8UMmMjWIDPrC4BJ5z1aluMt/UKeIaWCHD2/7ig+sxYN6HdWhaGpPEE4gt/9XkSx vhgA== X-Gm-Message-State: ABuFfohrMK9/zj7hhPba1od5tOj5wReL13hcxus6tUEJNkE1x1FbMRoS GXirHMAImsvXa2tKtacXg8er31Ix9BA= X-Google-Smtp-Source: ACcGV62j07/5v/sy3mFxfzY3tAFIG3GnQ/xT/3bLR62ni/pJdLKW1kevZG2JJvhKh8P6loC+gUPe6A== X-Received: by 2002:adf:e784:: with SMTP id n4-v6mr5085933wrm.187.1539339402817; Fri, 12 Oct 2018 03:16:42 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:42 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 01/13] mt76: move mt76x02_phy_set_bw in mt76x02-lib module Date: Fri, 12 Oct 2018 12:16:17 +0200 Message-Id: X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move mt76x02_phy_set_bw routine in mt76x02_phy.c since it is shared between mt76x0 and mt76x2 drivers and remove duplicated code Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 29 +------------------ .../net/wireless/mediatek/mt76/mt76x02_phy.c | 26 +++++++++++++++++ .../net/wireless/mediatek/mt76/mt76x02_phy.h | 1 + .../wireless/mediatek/mt76/mt76x2/mt76x2.h | 1 - .../wireless/mediatek/mt76/mt76x2/pci_phy.c | 2 +- .../net/wireless/mediatek/mt76/mt76x2/phy.c | 26 ----------------- .../wireless/mediatek/mt76/mt76x2/usb_phy.c | 2 +- 7 files changed, 30 insertions(+), 57 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 7c30ba47c7f4..3bc6d7b0914a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -214,33 +214,6 @@ int mt76x0_wait_bbp_ready(struct mt76x02_dev *dev) return 0; } -static void -mt76x0_bbp_set_ctrlch(struct mt76x02_dev *dev, enum nl80211_chan_width width, - u8 ctrl) -{ - int core_val, agc_val; - - switch (width) { - case NL80211_CHAN_WIDTH_80: - core_val = 3; - agc_val = 7; - break; - case NL80211_CHAN_WIDTH_40: - core_val = 2; - agc_val = 3; - break; - default: - core_val = 0; - agc_val = 1; - break; - } - - mt76_rmw_field(dev, MT_BBP(CORE, 1), MT_BBP_CORE_R1_BW, core_val); - mt76_rmw_field(dev, MT_BBP(AGC, 0), MT_BBP_AGC_R0_BW, agc_val); - mt76_rmw_field(dev, MT_BBP(AGC, 0), MT_BBP_AGC_R0_CTRL_CHAN, ctrl); - mt76_rmw_field(dev, MT_BBP(TXBE, 0), MT_BBP_TXBE_R0_CTRL_CHAN, ctrl); -} - static void mt76x0_vco_cal(struct mt76x02_dev *dev, u8 channel) { u8 val; @@ -681,7 +654,7 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, } mt76x0_bbp_set_bw(dev, chandef->width); - mt76x0_bbp_set_ctrlch(dev, chandef->width, ch_group_index); + mt76x02_phy_set_bw(dev, chandef->width, ch_group_index); mt76x0_mac_set_ctrlch(dev, ch_group_index & 1); mt76x0_ant_select(dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c index c398471b6376..3de7170db111 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c @@ -178,3 +178,29 @@ int mt76x02_phy_get_min_avg_rssi(struct mt76x02_dev *dev) return min_rssi; } EXPORT_SYMBOL_GPL(mt76x02_phy_get_min_avg_rssi); + +void mt76x02_phy_set_bw(struct mt76x02_dev *dev, int width, u8 ctrl) +{ + int core_val, agc_val; + + switch (width) { + case NL80211_CHAN_WIDTH_80: + core_val = 3; + agc_val = 7; + break; + case NL80211_CHAN_WIDTH_40: + core_val = 2; + agc_val = 3; + break; + default: + core_val = 0; + agc_val = 1; + break; + } + + mt76_rmw_field(dev, MT_BBP(CORE, 1), MT_BBP_CORE_R1_BW, core_val); + mt76_rmw_field(dev, MT_BBP(AGC, 0), MT_BBP_AGC_R0_BW, agc_val); + mt76_rmw_field(dev, MT_BBP(AGC, 0), MT_BBP_AGC_R0_CTRL_CHAN, ctrl); + mt76_rmw_field(dev, MT_BBP(TXBE, 0), MT_BBP_TXBE_R0_CTRL_CHAN, ctrl); +} +EXPORT_SYMBOL_GPL(mt76x02_phy_set_bw); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h index c370b4cc68ee..e0ca44ed5081 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h @@ -26,5 +26,6 @@ int mt76x02_get_max_rate_power(struct mt76_rate_power *r); void mt76x02_phy_set_rxpath(struct mt76x02_dev *dev); void mt76x02_phy_set_txdac(struct mt76x02_dev *dev); int mt76x02_phy_get_min_avg_rssi(struct mt76x02_dev *dev); +void mt76x02_phy_set_bw(struct mt76x02_dev *dev, int width, u8 ctrl); #endif /* __MT76x02_PHY_H */ diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h index cbec8c6f1b2d..8b18acafedb2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h @@ -100,7 +100,6 @@ void mt76x2_phy_set_txpower_regs(struct mt76x02_dev *dev, enum nl80211_band band); void mt76x2_configure_tx_delay(struct mt76x02_dev *dev, enum nl80211_band band, u8 bw); -void mt76x2_phy_set_bw(struct mt76x02_dev *dev, int width, u8 ctrl); void mt76x2_phy_set_band(struct mt76x02_dev *dev, int band, bool primary_upper); void mt76x2_apply_gain_adj(struct mt76x02_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c index dbb63d4c3bad..991db4f48d94 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c @@ -338,7 +338,7 @@ int mt76x2_phy_set_channel(struct mt76x02_dev *dev, mt76x2_phy_set_txpower(dev); mt76x2_phy_set_band(dev, chan->band, ch_group_index & 1); - mt76x2_phy_set_bw(dev, chandef->width, ch_group_index); + mt76x02_phy_set_bw(dev, chandef->width, ch_group_index); mt76_rmw(dev, MT_EXT_CCA_CFG, (MT_EXT_CCA_CFG_CCA0 | diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c index fd077e8d8dcb..dcb3381cab91 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c @@ -210,32 +210,6 @@ void mt76x2_configure_tx_delay(struct mt76x02_dev *dev, } EXPORT_SYMBOL_GPL(mt76x2_configure_tx_delay); -void mt76x2_phy_set_bw(struct mt76x02_dev *dev, int width, u8 ctrl) -{ - int core_val, agc_val; - - switch (width) { - case NL80211_CHAN_WIDTH_80: - core_val = 3; - agc_val = 7; - break; - case NL80211_CHAN_WIDTH_40: - core_val = 2; - agc_val = 3; - break; - default: - core_val = 0; - agc_val = 1; - break; - } - - mt76_rmw_field(dev, MT_BBP(CORE, 1), MT_BBP_CORE_R1_BW, core_val); - mt76_rmw_field(dev, MT_BBP(AGC, 0), MT_BBP_AGC_R0_BW, agc_val); - mt76_rmw_field(dev, MT_BBP(AGC, 0), MT_BBP_AGC_R0_CTRL_CHAN, ctrl); - mt76_rmw_field(dev, MT_BBP(TXBE, 0), MT_BBP_TXBE_R0_CTRL_CHAN, ctrl); -} -EXPORT_SYMBOL_GPL(mt76x2_phy_set_bw); - void mt76x2_phy_set_band(struct mt76x02_dev *dev, int band, bool primary_upper) { switch (band) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c index 422114de695a..ff2fd71a0c14 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c @@ -156,7 +156,7 @@ int mt76x2u_phy_set_channel(struct mt76x02_dev *dev, mt76x2_phy_set_txpower(dev); mt76x2_phy_set_band(dev, chan->band, ch_group_index & 1); - mt76x2_phy_set_bw(dev, chandef->width, ch_group_index); + mt76x02_phy_set_bw(dev, chandef->width, ch_group_index); mt76_rmw(dev, MT_EXT_CCA_CFG, (MT_EXT_CCA_CFG_CCA0 | From patchwork Fri Oct 12 10:16:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638397 X-Patchwork-Delegate: kvalo@adurom.com 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 C33F93CF1 for ; Fri, 12 Oct 2018 10:16:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFCA12B727 for ; Fri, 12 Oct 2018 10:16:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A429D2B930; Fri, 12 Oct 2018 10:16:47 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BB212B727 for ; Fri, 12 Oct 2018 10:16:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728425AbeJLRs1 (ORCPT ); Fri, 12 Oct 2018 13:48:27 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45706 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728284AbeJLRs0 (ORCPT ); Fri, 12 Oct 2018 13:48:26 -0400 Received: by mail-wr1-f65.google.com with SMTP id q5-v6so12816409wrw.12 for ; Fri, 12 Oct 2018 03:16:44 -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=pTc7z/Wu0FMDOE0vA7b+wH80oda7TWl6z1kOzZ2czZc=; b=sNxhRBK0PVY3gfilgPyLn+N73lkcnC6caePhOT38gCI96yNo9eXgueSNhO7MP++sg5 ojaSGTzY/YqZnSxNGZ9/OoNFoqmpbb1OP1aMPT3nI9L2XdahtJdtWqqn+daIDAacptRP CCK1VkUjIpBPGziE9BzqLiZ6szpWvmU1jYnAQbSYzcHcuvS9cOLGAUr5ReREHhXVdV+Z bfcflhxPojL+q3nf7AOVFd6PusbvdeMmLgaa98sL/xrBT+vwRjsdXIdjhAMgHT1JFxWg smzEx1W17pHeIE5hk2P7CdOo5UBYwUmoJWXZdTBw4KBUiGUCPP9WWYjXyKQITz8MCv7v SR5Q== X-Gm-Message-State: ABuFfoi0UYMkDoRPxGrZgCXh+5L3UA9Bd5sjl28tt3LpqKVBKZ6d8DO7 rclYwQN2KnwfZmmpVzLpe6mBhg== X-Google-Smtp-Source: ACcGV61jAlS7bzrhJsQKV+XWc7gIQHVJUBvXDgmuRoO2ImVM1kVvkWNf4CSRei92gRIn4SA6wzKs+Q== X-Received: by 2002:adf:a706:: with SMTP id c6-v6mr5082851wrd.56.1539339403830; Fri, 12 Oct 2018 03:16:43 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:43 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 02/13] mt76: move mt76x02_phy_set_band in mt76x02-lib module Date: Fri, 12 Oct 2018 12:16:18 +0200 Message-Id: <19adde6f543ab610f9d78070c034c17aa4e1deb9.1539338611.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move mt76x02_phy_set_band routine in mt76x02_phy.c since it is shared between mt76x0 and mt76x2 drivers and remove duplicated code Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 16 ++-------------- .../net/wireless/mediatek/mt76/mt76x02_phy.c | 19 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt76x02_phy.h | 2 ++ .../wireless/mediatek/mt76/mt76x2/mt76x2.h | 1 - .../wireless/mediatek/mt76/mt76x2/pci_phy.c | 2 +- .../net/wireless/mediatek/mt76/mt76x2/phy.c | 18 ------------------ .../wireless/mediatek/mt76/mt76x2/usb_phy.c | 2 +- 7 files changed, 25 insertions(+), 35 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 3bc6d7b0914a..638a2bca5cff 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -270,13 +270,6 @@ static void mt76x0_vco_cal(struct mt76x02_dev *dev, u8 channel) msleep(2); } -static void -mt76x0_mac_set_ctrlch(struct mt76x02_dev *dev, bool primary_upper) -{ - mt76_rmw_field(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_UPPER_40M, - primary_upper); -} - static void mt76x0_phy_set_band(struct mt76x02_dev *dev, enum nl80211_band band) { @@ -287,9 +280,6 @@ mt76x0_phy_set_band(struct mt76x02_dev *dev, enum nl80211_band band) rf_wr(dev, MT_RF(5, 0), 0x45); rf_wr(dev, MT_RF(6, 0), 0x44); - mt76_set(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_2G); - mt76_clear(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_5G); - mt76_wr(dev, MT_TX_ALC_VGA3, 0x00050007); mt76_wr(dev, MT_TX0_RF_GAIN_CORR, 0x003E0002); break; @@ -299,9 +289,6 @@ mt76x0_phy_set_band(struct mt76x02_dev *dev, enum nl80211_band band) rf_wr(dev, MT_RF(5, 0), 0x44); rf_wr(dev, MT_RF(6, 0), 0x45); - mt76_clear(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_2G); - mt76_set(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_5G); - mt76_wr(dev, MT_TX_ALC_VGA3, 0x00000005); mt76_wr(dev, MT_TX0_RF_GAIN_CORR, 0x01010102); break; @@ -655,7 +642,8 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, mt76x0_bbp_set_bw(dev, chandef->width); mt76x02_phy_set_bw(dev, chandef->width, ch_group_index); - mt76x0_mac_set_ctrlch(dev, ch_group_index & 1); + mt76x02_phy_set_band(dev, chandef->chan->band, + ch_group_index & 1); mt76x0_ant_select(dev); mt76_rmw(dev, MT_EXT_CCA_CFG, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c index 3de7170db111..b0c78ab97ad7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c @@ -204,3 +204,22 @@ void mt76x02_phy_set_bw(struct mt76x02_dev *dev, int width, u8 ctrl) mt76_rmw_field(dev, MT_BBP(TXBE, 0), MT_BBP_TXBE_R0_CTRL_CHAN, ctrl); } EXPORT_SYMBOL_GPL(mt76x02_phy_set_bw); + +void mt76x02_phy_set_band(struct mt76x02_dev *dev, int band, + bool primary_upper) +{ + switch (band) { + case NL80211_BAND_2GHZ: + mt76_set(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_2G); + mt76_clear(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_5G); + break; + case NL80211_BAND_5GHZ: + mt76_clear(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_2G); + mt76_set(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_5G); + break; + } + + mt76_rmw_field(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_UPPER_40M, + primary_upper); +} +EXPORT_SYMBOL_GPL(mt76x02_phy_set_band); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h index e0ca44ed5081..1a20c1852dbf 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h @@ -27,5 +27,7 @@ void mt76x02_phy_set_rxpath(struct mt76x02_dev *dev); void mt76x02_phy_set_txdac(struct mt76x02_dev *dev); int mt76x02_phy_get_min_avg_rssi(struct mt76x02_dev *dev); void mt76x02_phy_set_bw(struct mt76x02_dev *dev, int width, u8 ctrl); +void mt76x02_phy_set_band(struct mt76x02_dev *dev, int band, + bool primary_upper); #endif /* __MT76x02_PHY_H */ diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h index 8b18acafedb2..ab93125f46de 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/mt76x2.h @@ -100,7 +100,6 @@ void mt76x2_phy_set_txpower_regs(struct mt76x02_dev *dev, enum nl80211_band band); void mt76x2_configure_tx_delay(struct mt76x02_dev *dev, enum nl80211_band band, u8 bw); -void mt76x2_phy_set_band(struct mt76x02_dev *dev, int band, bool primary_upper); void mt76x2_apply_gain_adj(struct mt76x02_dev *dev); #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c index 991db4f48d94..5942cc7a98a3 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c @@ -337,7 +337,7 @@ int mt76x2_phy_set_channel(struct mt76x02_dev *dev, mt76x2_configure_tx_delay(dev, band, bw); mt76x2_phy_set_txpower(dev); - mt76x2_phy_set_band(dev, chan->band, ch_group_index & 1); + mt76x02_phy_set_band(dev, chan->band, ch_group_index & 1); mt76x02_phy_set_bw(dev, chandef->width, ch_group_index); mt76_rmw(dev, MT_EXT_CCA_CFG, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c index dcb3381cab91..e9fff5b7f125 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/phy.c @@ -210,24 +210,6 @@ void mt76x2_configure_tx_delay(struct mt76x02_dev *dev, } EXPORT_SYMBOL_GPL(mt76x2_configure_tx_delay); -void mt76x2_phy_set_band(struct mt76x02_dev *dev, int band, bool primary_upper) -{ - switch (band) { - case NL80211_BAND_2GHZ: - mt76_set(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_2G); - mt76_clear(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_5G); - break; - case NL80211_BAND_5GHZ: - mt76_clear(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_2G); - mt76_set(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_5G); - break; - } - - mt76_rmw_field(dev, MT_TX_BAND_CFG, MT_TX_BAND_CFG_UPPER_40M, - primary_upper); -} -EXPORT_SYMBOL_GPL(mt76x2_phy_set_band); - void mt76x2_phy_tssi_compensate(struct mt76x02_dev *dev, bool wait) { struct ieee80211_channel *chan = dev->mt76.chandef.chan; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c index ff2fd71a0c14..c0c8c0ad1912 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c @@ -155,7 +155,7 @@ int mt76x2u_phy_set_channel(struct mt76x02_dev *dev, mt76x2_configure_tx_delay(dev, chan->band, bw); mt76x2_phy_set_txpower(dev); - mt76x2_phy_set_band(dev, chan->band, ch_group_index & 1); + mt76x02_phy_set_band(dev, chan->band, ch_group_index & 1); mt76x02_phy_set_bw(dev, chandef->width, ch_group_index); mt76_rmw(dev, MT_EXT_CCA_CFG, From patchwork Fri Oct 12 10:16:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638399 X-Patchwork-Delegate: kvalo@adurom.com 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 DD3B0157A for ; Fri, 12 Oct 2018 10:16:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD17128066 for ; Fri, 12 Oct 2018 10:16:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B58FC2B8FD; Fri, 12 Oct 2018 10:16:47 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A9A628066 for ; Fri, 12 Oct 2018 10:16:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728430AbeJLRs1 (ORCPT ); Fri, 12 Oct 2018 13:48:27 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44219 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728366AbeJLRs1 (ORCPT ); Fri, 12 Oct 2018 13:48:27 -0400 Received: by mail-wr1-f67.google.com with SMTP id 63-v6so12812704wra.11 for ; Fri, 12 Oct 2018 03:16:45 -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=D/YmYOAVr/RO6b56NB6/u7RzOApU4JVjt8zBK+ZR/Lo=; b=JvYIbbiRIqsmhEejkrK7qHS5jYK1qyvuXFNmWxfH7CTh98PwaKNUY1+xLo8OG7ElRC hObUkV3Yzdya/+r8WS7Pcj13vWF4SoGjOoxB3Q9EM77kZPFHtm6ZcmPK76c1L3h3tsVd rUO9dIBt378qHmGCRzHXjkke6nueopcKlHDGvmPmqb8Y5CNjw8OIw1+D/3+cc0fU1N0u 24jLNcjBQXkvfMUsUsNAUJ0FeUwDMzEb8bejyVeFiAz+EzpKD/0EX8OvnNLI9qCXrZwt x5+COZ3AV7vAsMM78ow3HRNXaAFJO7DwVNR85fnhELCZ6ynjRw3yOCPfukgKBrEufIVW tJxQ== X-Gm-Message-State: ABuFfoi1xqO9pkiEr9xfF32TZbPAFsnFKWLwK+Sx0fKx31yelmyv8r5G Ft946057zdBVTkqTQgREJS2ev0ZMYrU= X-Google-Smtp-Source: ACcGV61/sb5gwPH+fvFsVkK76xBAGHkxoW6eos9alPFstX7frUsO3DTx5uxqDkfVOQ9zeut7cibEJA== X-Received: by 2002:adf:f84e:: with SMTP id d14-v6mr4747175wrq.174.1539339404797; Fri, 12 Oct 2018 03:16:44 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:44 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 03/13] mt76x0: pci: rename mt76x0_phy_calibrate Date: Fri, 12 Oct 2018 12:16:19 +0200 Message-Id: <6572922b3472d21b6ad4da512ffd4738687872d6.1539338611.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rename mt76x0_phy_calibrate routine in mt76x0_phy_calibration_work in order to not collide with calibration routine for mt76x0e Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 638a2bca5cff..9a8e1fcee26b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -787,7 +787,7 @@ static void mt76x0_dynamic_vga_tuning(struct mt76x02_dev *dev) mt76_wr(dev, MT_BBP(AGC,8), val); } -static void mt76x0_phy_calibrate(struct work_struct *work) +static void mt76x0_phy_calibration_work(struct work_struct *work) { struct mt76x02_dev *dev = container_of(work, struct mt76x02_dev, cal_work.work); @@ -854,7 +854,7 @@ static void mt76x0_rf_init(struct mt76x02_dev *dev) void mt76x0_phy_init(struct mt76x02_dev *dev) { - INIT_DELAYED_WORK(&dev->cal_work, mt76x0_phy_calibrate); + INIT_DELAYED_WORK(&dev->cal_work, mt76x0_phy_calibration_work); mt76x0_rf_init(dev); mt76x02_phy_set_rxpath(dev); From patchwork Fri Oct 12 10:16:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638401 X-Patchwork-Delegate: kvalo@adurom.com 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 A832C157A for ; Fri, 12 Oct 2018 10:16:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9473B2B727 for ; Fri, 12 Oct 2018 10:16:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 883632B930; Fri, 12 Oct 2018 10:16:49 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DFD02B727 for ; Fri, 12 Oct 2018 10:16:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728442AbeJLRs3 (ORCPT ); Fri, 12 Oct 2018 13:48:29 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43020 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728426AbeJLRs2 (ORCPT ); Fri, 12 Oct 2018 13:48:28 -0400 Received: by mail-wr1-f68.google.com with SMTP id n1-v6so12810109wrt.10 for ; Fri, 12 Oct 2018 03:16:46 -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=sMrbuVWxMZIXH9fBXlBOhvFBSqcfBOeh0Dbr0uv9+eM=; b=n/4RBpTw2bY/oLVMMtJsRO6q5oNbdhygvh42/N3yiwf5GZ1HyFtZncuvKbFM96LbmM rT9qvfvAL3eFe3H7NfLid4Rlg5G8G1oLMu206qGG/PX9LHQaT6Uoh8oc9XG6U/glSvVG I39TsX5YXWLD6xlAEL1dtDa1rU+WYZR5DZrmlIvr0K/su+IolNvumjDlN0tudHteedaF ROk/ZrCcK46tFqekXQCo9zuBPyotmVjFsUiz23QRhtQtrWTXKJndFd2Haq7UNzYbLZHz tWQWIN4nd8s7zDbr3X5d4a8iC341sHl98AFOeGqmWET7MJBBg0jF5Rfvsdofd/poYlAf b9Cg== X-Gm-Message-State: ABuFfoiyVq7U6eABs3+J0RL/PpRIAqkeb98N9GEDYfTltj5V0jnvBwJw QUAhtKJmgMuNHvmhTc4IODfqdIQ1Ayw= X-Google-Smtp-Source: ACcGV63CyhWItqKsDDZTeWf4YcG6VvlZPeNd2s9bc2CYv5bXCxsvSyQLldG0EENPMFXphQy1RYr/EA== X-Received: by 2002:a5d:438e:: with SMTP id i14-v6mr5068822wrq.156.1539339405829; Fri, 12 Oct 2018 03:16:45 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:45 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 04/13] mt76x0: pci: introduce mt76x0_phy_calirate routine Date: Fri, 12 Oct 2018 12:16:20 +0200 Message-Id: <326458a15d0c242e7419e3bfc0033ccdc9083676.1539338611.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add mt76x0_phy_calirate routine in order to perform phy calibration for mt76x0e devices. Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/mcu.h | 3 ++ .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 1 + .../net/wireless/mediatek/mt76/mt76x0/pci.c | 1 + .../net/wireless/mediatek/mt76/mt76x0/phy.c | 53 +++++++++++++++++-- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h index b66e70f6cd89..3b34e1d2769f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.h @@ -39,6 +39,9 @@ enum mcu_calibrate { MCU_CAL_TXDCOC, MCU_CAL_RX_GROUP_DELAY, MCU_CAL_TX_GROUP_DELAY, + MCU_CAL_VCO, + MCU_CAL_NO_SIGNAL = 0xfe, + MCU_CAL_FULL = 0xff, }; int mt76x0e_mcu_init(struct mt76x02_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index 1bff2be45a13..6717d83e0ff6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -72,6 +72,7 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef); void mt76x0_phy_recalibrate_after_assoc(struct mt76x02_dev *dev); void mt76x0_phy_set_txpower(struct mt76x02_dev *dev); +void mt76x0_phy_calibrate(struct mt76x02_dev *dev, bool power_on); /* MAC */ void mt76x0_mac_work(struct work_struct *work); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c index 10845f37af37..f31c63444c82 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c @@ -28,6 +28,7 @@ static int mt76x0e_start(struct ieee80211_hw *hw) mutex_lock(&dev->mt76.mutex); mt76x02_mac_start(dev); + mt76x0_phy_calibrate(dev, true); ieee80211_queue_delayed_work(dev->mt76.hw, &dev->mac_work, MT_CALIBRATE_INTERVAL); ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 9a8e1fcee26b..6bd5aa67d400 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -581,6 +581,48 @@ void mt76x0_phy_set_txpower(struct mt76x02_dev *dev) mt76x02_phy_set_txpower(dev, info[0], info[1]); } +void mt76x0_phy_calibrate(struct mt76x02_dev *dev, bool power_on) +{ + struct ieee80211_channel *chan = dev->mt76.chandef.chan; + u32 val, tx_alc, reg_val; + + if (power_on) { + mt76x02_mcu_calibrate(dev, MCU_CAL_R, 0, false); + mt76x02_mcu_calibrate(dev, MCU_CAL_VCO, chan->hw_value, + false); + usleep_range(10, 20); + /* XXX: tssi */ + } + + tx_alc = mt76_rr(dev, MT_TX_ALC_CFG_0); + mt76_wr(dev, MT_TX_ALC_CFG_0, 0); + usleep_range(500, 700); + + reg_val = mt76_rr(dev, MT_BBP(IBI, 9)); + mt76_wr(dev, MT_BBP(IBI, 9), 0xffffff7e); + + if (chan->band == NL80211_BAND_5GHZ) { + if (chan->hw_value < 100) + val = 0x701; + else if (chan->hw_value < 140) + val = 0x801; + else + val = 0x901; + } else { + val = 0x600; + } + + mt76x02_mcu_calibrate(dev, MCU_CAL_FULL, val, false); + msleep(350); + mt76x02_mcu_calibrate(dev, MCU_CAL_LC, 1, false); + usleep_range(15000, 20000); + + mt76_wr(dev, MT_BBP(IBI, 9), reg_val); + mt76_wr(dev, MT_TX_ALC_CFG_0, tx_alc); + mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1, false); +} +EXPORT_SYMBOL_GPL(mt76x0_phy_calibrate); + int mt76x0_phy_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef) { @@ -671,9 +713,14 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, /* Vendor driver don't do it */ /* mt76x0_phy_set_tx_power(dev, channel, rf_bw_band); */ - mt76x0_vco_cal(dev, channel); - if (scan) - mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1, false); + if (mt76_is_usb(dev)) { + mt76x0_vco_cal(dev, channel); + if (scan) + mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1, + false); + } else { + mt76x0_phy_calibrate(dev, false); + } mt76x0_phy_set_txpower(dev); From patchwork Fri Oct 12 10:16:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638403 X-Patchwork-Delegate: kvalo@adurom.com 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 7759414E2 for ; Fri, 12 Oct 2018 10:16:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 678062B727 for ; Fri, 12 Oct 2018 10:16:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BEE22B8FD; Fri, 12 Oct 2018 10:16:50 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0946E2B727 for ; Fri, 12 Oct 2018 10:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728446AbeJLRs3 (ORCPT ); Fri, 12 Oct 2018 13:48:29 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38345 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728366AbeJLRs3 (ORCPT ); Fri, 12 Oct 2018 13:48:29 -0400 Received: by mail-wr1-f66.google.com with SMTP id a13-v6so12828275wrt.5 for ; Fri, 12 Oct 2018 03:16:47 -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=2ATLtAkzcEPk5OCpxxTHw0LmyDdWBGlGPeZAMdvHGt8=; b=DPOQBm+OsqUJ1xgTAaF1/g/UmxHASG9ix+OV1/ushLorUFMtIk4MdIHBT9mIDej/nN GeYcu5hC50bBgqzLua6GEoLTO7Vyy+AhJVkKMEXm2Q5fYhX7jcS4+aMIuuInVy0RkTkk 4Sx3RJvvWzCCwYnvA0j4tVUXIE5oeXHSCwJYSP10wcukTnqf+i0yeEZ9KEFIeojiEuCV QR1TL7werBn13DEYTJaYlKCQ31ZfB4Fx5DCZVlmvCpQlM9+DUVISysv4IdbtLK1LuyoF um9m6q8Yw6Vi12ipnSsVZODFcwQb/ig59sSkyjvYGyP7rYefB3JuJ5yMPz4wADeEvTfU i2NA== X-Gm-Message-State: ABuFfogqwU9zk1sZ8nG2McRCpon8g1aVZcnAH+ib9oYIfFgTG1k2KwcU Xlnf92YJJODydp239K6qlPlnAMdX/ns= X-Google-Smtp-Source: ACcGV61JLBI2l8KyqjM6FjQQVCkAgKNWfdKYv2UO4Caukc6yc64qWEv6njC+cbuI7Rl238ZLDNYLkw== X-Received: by 2002:adf:92e6:: with SMTP id 93-v6mr5004934wrn.124.1539339406765; Fri, 12 Oct 2018 03:16:46 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:46 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 05/13] mt76x0: phy: update set_channel for mt76x0e devices Date: Fri, 12 Oct 2018 12:16:21 +0200 Message-Id: X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Do not run mt76x0_vco_cal and mt76x0_bbp_set_bw routines and configure MT_TX_SW_CFG0 register for pcie devices in mt76x0_phy_set_channel function. Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 6bd5aa67d400..fddfdb1e1756 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -682,7 +682,16 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, break; } - mt76x0_bbp_set_bw(dev, chandef->width); + if (mt76_is_usb(dev)) { + mt76x0_bbp_set_bw(dev, chandef->width); + } else { + if (chandef->width == NL80211_CHAN_WIDTH_80 || + chandef->width == NL80211_CHAN_WIDTH_40) + val = 0x201; + else + val = 0x601; + mt76_wr(dev, MT_TX_SW_CFG0, val); + } mt76x02_phy_set_bw(dev, chandef->width, ch_group_index); mt76x02_phy_set_band(dev, chandef->chan->band, ch_group_index & 1); @@ -698,7 +707,6 @@ int mt76x0_phy_set_channel(struct mt76x02_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)); @@ -708,17 +716,17 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, val &= ~0x20; mt76_wr(dev, MT_BBP(CORE, 1), val); + mt76x0_read_rx_gain(dev); mt76x0_phy_set_chan_bbp_params(dev, rf_bw_band); - /* Vendor driver don't do it */ - /* mt76x0_phy_set_tx_power(dev, channel, rf_bw_band); */ - if (mt76_is_usb(dev)) { mt76x0_vco_cal(dev, channel); if (scan) mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1, false); } else { + /* enable vco */ + rf_set(dev, MT_RF(0, 4), BIT(7)); mt76x0_phy_calibrate(dev, false); } From patchwork Fri Oct 12 10:16:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638405 X-Patchwork-Delegate: kvalo@adurom.com 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 41D0814E2 for ; Fri, 12 Oct 2018 10:16:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3192E2B727 for ; Fri, 12 Oct 2018 10:16:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25B592B8FD; Fri, 12 Oct 2018 10:16:52 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98F5B2B727 for ; Fri, 12 Oct 2018 10:16:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728450AbeJLRsb (ORCPT ); Fri, 12 Oct 2018 13:48:31 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43021 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728435AbeJLRsa (ORCPT ); Fri, 12 Oct 2018 13:48:30 -0400 Received: by mail-wr1-f66.google.com with SMTP id n1-v6so12810208wrt.10 for ; Fri, 12 Oct 2018 03:16:48 -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=3ynAmKHhaCLut07COhXSyOAuapRPV6d2juTunQJTZHE=; b=BD4OwqmTtMtHedngWSukhD74A3Yfxemuw6JioTBZ9tDNmQfo1d88XxGKWqswBwYrH4 SvY8qczZ+SzbxtXuRTLTgAAXyml1LedjlL/j3iCvU0QSHrtPyMo6y8g5b/NyjdI9YZ7Q Yuyvz09frWew1G+5vZ79TFmh4/3SoiU5CVxBF/EmzM24E0DmexbC3iF+IPyUAEjHIVRB ZE/qNmrqyyf9jym8tV+jVLBv25GPnDIDP775zUzYVUJnp1sKNbx/V1TFj6DjP2BuS69n rPgGVCtqBBu9MDUfVCfRZcAvoLwq/JMYiOcEYatqyHKJze1M6qFmA4dHL9RKsuck7r8Y 37Ew== X-Gm-Message-State: ABuFfoicyc2oIBIIx5f3nk+oiKfP5DB70l+E175RiZl2ZXx4j8xkJm5v gKchCwDwG8CdjSsYzfcx9LXuzA== X-Google-Smtp-Source: ACcGV63fD18oJiPKv0nLvxtlwMr9T9rXcuB2fHgoj778lZ24zyrxvtgPDEZv23aPbQQD0pVtXqgz9A== X-Received: by 2002:adf:f6c4:: with SMTP id y4-v6mr5086299wrp.79.1539339407682; Fri, 12 Oct 2018 03:16:47 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:47 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 06/13] mt76x0: eeprom: introduce mt76x0_tssi_enabled routine Date: Fri, 12 Oct 2018 12:16:22 +0200 Message-Id: X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add mt76x0_tssi_enabled in order to check if tssi compensation is enabled since mt76x0 condition differs from mt76x2 one. Moreover move back mt76x02_temp_tx_alc_enabled and mt76x02_tssi_enabled routines in mt76x2/eeprom.h since they are mt76x2 specific Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 2 +- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 6 ++++++ .../wireless/mediatek/mt76/mt76x02_eeprom.h | 21 ------------------- .../wireless/mediatek/mt76/mt76x2/eeprom.c | 4 ++-- .../wireless/mediatek/mt76/mt76x2/eeprom.h | 21 +++++++++++++++++++ .../wireless/mediatek/mt76/mt76x2/pci_phy.c | 4 ++-- .../wireless/mediatek/mt76/mt76x2/usb_phy.c | 2 +- 7 files changed, 33 insertions(+), 27 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 1defb072ccbf..ab4fd6e0f23a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -135,7 +135,7 @@ static s8 mt76x0_get_delta(struct mt76x02_dev *dev) struct cfg80211_chan_def *chandef = &dev->mt76.chandef; u8 val; - if (mt76x02_tssi_enabled(dev)) + if (mt76x0_tssi_enabled(dev)) return 0; if (chandef->width == NL80211_CHAN_WIDTH_80) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index 40fd4e61769b..ee9ade9f3c8b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -37,4 +37,10 @@ static inline s8 s6_to_s8(u32 val) return ret; } +static inline bool mt76x0_tssi_enabled(struct mt76x02_dev *dev) +{ + return (mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) & + MT_EE_NIC_CONF_1_TX_ALC_EN); +} + #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 0fba43d569b5..b3ec74835d10 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -179,27 +179,6 @@ mt76x02_eeprom_get(struct mt76x02_dev *dev, return get_unaligned_le16(dev->mt76.eeprom.data + field); } -static inline bool -mt76x02_temp_tx_alc_enabled(struct mt76x02_dev *dev) -{ - u16 val; - - val = mt76x02_eeprom_get(dev, MT_EE_TX_POWER_EXT_PA_5G); - if (!(val & BIT(15))) - return false; - - return mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) & - MT_EE_NIC_CONF_1_TEMP_TX_ALC; -} - -static inline bool -mt76x02_tssi_enabled(struct mt76x02_dev *dev) -{ - return !mt76x02_temp_tx_alc_enabled(dev) && - (mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) & - MT_EE_NIC_CONF_1_TX_ALC_EN); -} - bool mt76x02_ext_pa_enabled(struct mt76x02_dev *dev, enum nl80211_band band); int mt76x02_get_efuse_data(struct mt76x02_dev *dev, u16 base, void *buf, int len, enum mt76x02_eeprom_modes mode); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.c index 5fb9532f3eed..f39b622d03f4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.c @@ -464,7 +464,7 @@ void mt76x2_get_power_info(struct mt76x02_dev *dev, MT_EE_TX_POWER_1_START_2G); } - if (mt76x02_tssi_enabled(dev) || + if (mt76x2_tssi_enabled(dev) || !mt76x02_field_valid(t->target_power)) t->target_power = t->chain[0].target_power; @@ -481,7 +481,7 @@ int mt76x2_get_temp_comp(struct mt76x02_dev *dev, struct mt76x2_temp_comp *t) memset(t, 0, sizeof(*t)); - if (!mt76x02_temp_tx_alc_enabled(dev)) + if (!mt76x2_temp_tx_alc_enabled(dev)) return -EINVAL; if (!mt76x02_ext_pa_enabled(dev, band)) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.h index 13bceb6aa5e4..9e735524d367 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/eeprom.h @@ -70,4 +70,25 @@ mt76x2_has_ext_lna(struct mt76x02_dev *dev) return val & MT_EE_NIC_CONF_1_LNA_EXT_5G; } +static inline bool +mt76x2_temp_tx_alc_enabled(struct mt76x02_dev *dev) +{ + u16 val; + + val = mt76x02_eeprom_get(dev, MT_EE_TX_POWER_EXT_PA_5G); + if (!(val & BIT(15))) + return false; + + return mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) & + MT_EE_NIC_CONF_1_TEMP_TX_ALC; +} + +static inline bool +mt76x2_tssi_enabled(struct mt76x02_dev *dev) +{ + return !mt76x2_temp_tx_alc_enabled(dev) && + (mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) & + MT_EE_NIC_CONF_1_TX_ALC_EN); +} + #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c index 5942cc7a98a3..55708b8e6e10 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c @@ -26,7 +26,7 @@ mt76x2_phy_tssi_init_cal(struct mt76x02_dev *dev) struct ieee80211_channel *chan = dev->mt76.chandef.chan; u32 flag = 0; - if (!mt76x02_tssi_enabled(dev)) + if (!mt76x2_tssi_enabled(dev)) return false; if (mt76x2_channel_silent(dev)) @@ -391,7 +391,7 @@ int mt76x2_phy_set_channel(struct mt76x02_dev *dev, sizeof(dev->cal.agc_gain_cur)); /* init default values for temp compensation */ - if (mt76x02_tssi_enabled(dev)) { + if (mt76x2_tssi_enabled(dev)) { mt76_rmw_field(dev, MT_TX_ALC_CFG_1, MT_TX_ALC_CFG_1_TEMP_COMP, 0x38); mt76_rmw_field(dev, MT_TX_ALC_CFG_2, MT_TX_ALC_CFG_2_TEMP_COMP, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c index c0c8c0ad1912..ca96ba60510e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_phy.c @@ -202,7 +202,7 @@ int mt76x2u_phy_set_channel(struct mt76x02_dev *dev, if (scan) return 0; - if (mt76x02_tssi_enabled(dev)) { + if (mt76x2_tssi_enabled(dev)) { /* init default values for temp compensation */ mt76_rmw_field(dev, MT_TX_ALC_CFG_1, MT_TX_ALC_CFG_1_TEMP_COMP, 0x38); From patchwork Fri Oct 12 10:16:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638409 X-Patchwork-Delegate: kvalo@adurom.com 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 8090E157A for ; Fri, 12 Oct 2018 10:16:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C6F92B727 for ; Fri, 12 Oct 2018 10:16:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60BE62B8FD; Fri, 12 Oct 2018 10:16:54 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBA742B727 for ; Fri, 12 Oct 2018 10:16:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728464AbeJLRsd (ORCPT ); Fri, 12 Oct 2018 13:48:33 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33955 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728366AbeJLRsb (ORCPT ); Fri, 12 Oct 2018 13:48:31 -0400 Received: by mail-wm1-f68.google.com with SMTP id z25-v6so17717153wmf.1 for ; Fri, 12 Oct 2018 03:16:49 -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=XcphxZV7G8+kGnH7VVGVuTVDJeyCnUZyh8mK2HO6WGM=; b=aeBiFfEeSDn6RGkxcvuMjZy5ohkvxeWtyBh0W46pa3vSZRp8gPVvcIh8gs7TxVwVMz 6LPoRD3bp9SdbvyLZxWpYcrH7fzwpYS3LU4SoQRTVxOttEsmb6MqDHkeg3Z6jaDg4ZOO eAoPJLUIGAyzKnfkj8qC4aaKE7r2yG7+7SDFWsuw9jMqoS+s53Qk0PMB6X/InqpSh9W0 ExYIz/yY+X9cM9rBVynqOkTshcGXrbKtloEdunLmyAWVtkime9BDlFXbtPcZGOQVWFzL f/GDc/HQ61PJbQFjqDwpj9XHlmD92muHr2+oJ8f15JxaEoKZh4rjhQ1jTVq50h204amX rqng== X-Gm-Message-State: ABuFfogBmY+tFGm/wmBg2UfWI7cmnr3m8G/pC68t+XUS850dcmsua3lU jvXDzs633GQOjTPltRmpwM6NUQ== X-Google-Smtp-Source: ACcGV63f6ptUH+vxEu9JsPq+MJ1e/KoTLgXviuVg4+Md5FGeiTHj33t+oNsvP+gYPNYDeo5dKx3voQ== X-Received: by 2002:a1c:e717:: with SMTP id e23-v6mr4740935wmh.145.1539339408725; Fri, 12 Oct 2018 03:16:48 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:48 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 07/13] mt76x0: phy: add phy/vco temperature compensation Date: Fri, 12 Oct 2018 12:16:23 +0200 Message-Id: <7efacc28a7a4d1c157d387eba21040c34b0d1806.1539338611.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce phy/vco temperature calibration. Moreover fix configuration of register 67 on bank0 during temperature reading and use mt76_poll utility routine to poll core34 register. Furthermore temperature compensation needs to be disabled if the device supports tssi compensation. This issue has never been hit since temperature reading is not actually used by usb code. Fixes: 10de7a8b4ab9 ("mt76x0: phy files") Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 48 +++++++++---------- drivers/net/wireless/mediatek/mt76/mt76x02.h | 3 +- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index fddfdb1e1756..7d29fd16342a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -14,6 +14,9 @@ * GNU General Public License for more details. */ +#include +#include + #include "mt76x0.h" #include "mcu.h" #include "eeprom.h" @@ -23,8 +26,6 @@ #include "initvals_phy.h" #include "../mt76x02_phy.h" -#include - static int mt76x0_rf_csr_wr(struct mt76x02_dev *dev, u32 offset, u8 value) { @@ -782,45 +783,41 @@ void mt76x0_agc_restore(struct mt76x02_dev *dev) static void mt76x0_temp_sensor(struct mt76x02_dev *dev) { u8 rf_b7_73, rf_b0_66, rf_b0_67; - int cycle, temp; - u32 val; - s32 sval; + s8 val; rf_b7_73 = rf_rr(dev, MT_RF(7, 73)); rf_b0_66 = rf_rr(dev, MT_RF(0, 66)); - rf_b0_67 = rf_rr(dev, MT_RF(0, 73)); + rf_b0_67 = rf_rr(dev, MT_RF(0, 67)); rf_wr(dev, MT_RF(7, 73), 0x02); rf_wr(dev, MT_RF(0, 66), 0x23); - rf_wr(dev, MT_RF(0, 73), 0x01); + rf_wr(dev, MT_RF(0, 67), 0x01); mt76_wr(dev, MT_BBP(CORE, 34), 0x00080055); - for (cycle = 0; cycle < 2000; cycle++) { - val = mt76_rr(dev, MT_BBP(CORE, 34)); - if (!(val & 0x10)) - break; - udelay(3); - } - - if (cycle >= 2000) { - val &= 0x10; - mt76_wr(dev, MT_BBP(CORE, 34), val); + if (!mt76_poll(dev, MT_BBP(CORE, 34), BIT(4), 0, 2000)) { + mt76_clear(dev, MT_BBP(CORE, 34), BIT(4)); goto done; } - sval = mt76_rr(dev, MT_BBP(CORE, 35)) & 0xff; - if (!(sval & 0x80)) - sval &= 0x7f; /* Positive */ - else - sval |= 0xffffff00; /* Negative */ + val = mt76_rr(dev, MT_BBP(CORE, 35)); + val = (35 * (val - dev->cal.rx.temp_offset)) / 10 + 25; - temp = (35 * (sval - dev->cal.rx.temp_offset)) / 10 + 25; + if (abs(val - dev->cal.temp_vco) > 20) { + mt76x02_mcu_calibrate(dev, MCU_CAL_VCO, + dev->mt76.chandef.chan->hw_value, + false); + dev->cal.temp_vco = val; + } + if (abs(val - dev->cal.temp) > 30) { + mt76x0_phy_calibrate(dev, false); + dev->cal.temp = val; + } done: rf_wr(dev, MT_RF(7, 73), rf_b7_73); rf_wr(dev, MT_RF(0, 66), rf_b0_66); - rf_wr(dev, MT_RF(0, 73), rf_b0_67); + rf_wr(dev, MT_RF(0, 67), rf_b0_67); } static void mt76x0_dynamic_vga_tuning(struct mt76x02_dev *dev) @@ -848,7 +845,8 @@ static void mt76x0_phy_calibration_work(struct work_struct *work) cal_work.work); mt76x0_dynamic_vga_tuning(dev); - mt76x0_temp_sensor(dev); + if (!mt76x0_tssi_enabled(dev)) + mt76x0_temp_sensor(dev); ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, MT_CALIBRATE_INTERVAL); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02.h b/drivers/net/wireless/mediatek/mt76/mt76x02.h index fe731529144c..f375fdcbd2bf 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02.h @@ -55,7 +55,8 @@ struct mt76x02_calibration { s8 agc_gain_adjust; s8 low_gain; - u8 temp; + s8 temp_vco; + s8 temp; bool init_cal_done; bool tssi_cal_done; From patchwork Fri Oct 12 10:16:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638407 X-Patchwork-Delegate: kvalo@adurom.com 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 DDECF157A for ; Fri, 12 Oct 2018 10:16:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE51B2B727 for ; Fri, 12 Oct 2018 10:16:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C29982B8FD; Fri, 12 Oct 2018 10:16:52 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68D762B727 for ; Fri, 12 Oct 2018 10:16:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728452AbeJLRsc (ORCPT ); Fri, 12 Oct 2018 13:48:32 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39798 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728447AbeJLRsb (ORCPT ); Fri, 12 Oct 2018 13:48:31 -0400 Received: by mail-wm1-f68.google.com with SMTP id y144-v6so12317420wmd.4 for ; Fri, 12 Oct 2018 03:16:50 -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=qR+uKpaaCgGMjthr8Yfn4/BLbCmOB28YTW/lMus9v4M=; b=kjrzEriIvOkFKeXZjG/Mx6vJNBZZikESflER7Cd8D8SAhAzhgnO+ZaUiOT/IajuwPk 5dm82nfNx33kXSbPtAGCV3x0tcXvr0IUkTekU88Z8Ymkt5mBwWJEYwIlEPq+1PX9l9Ci DSZfyqK3YjCUnHRYTPPF6a0Cqe1cXY8PH607h0SHyydyPZfIVYR556GvZKMVFbVx37/g /QKV13pCR4m9OJ80LzqJkWLHJTWOji7/9sAlRAckCd3ZVLte7+8F9cQsX5/Hzg2ldhBx wXaQRdOgs7IXqKaBqjp3XM3Py06akMWWtWG/sFMtcyACrHMijCOkTFvrEzgzo7qGrxzs 1Mnw== X-Gm-Message-State: ABuFfoglJKwE+4pKVpdgtgLo48NVEIWA7r+gwXqkSoPaglXsj/ZS67xT 9CDpiMLK1Gd/gjA0fpFpAActVd75oNU= X-Google-Smtp-Source: ACcGV619ogJBRiIZV11+s2L2yOcvVEeK1PHP8hwgyHypjzuiFo0fL1287TFC4tc2JN/m2557pa0p2g== X-Received: by 2002:a1c:930c:: with SMTP id v12-v6mr4925824wmd.9.1539339409842; Fri, 12 Oct 2018 03:16:49 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:49 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 08/13] mt76: move rssi_gain_thresh routines in mt76x02-lib module Date: Fri, 12 Oct 2018 12:16:24 +0200 Message-Id: <858960276a465841df8aea8046e0a9a671396d1c.1539338611.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move mt76x2_get_rssi_gain_thresh and mt76x2_get_low_rssi_gain_thresh routines in mt76x02-lib module in order to be reused by mt76x0 driver for dynamic vga calibration Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x02_phy.h | 26 ++++++++++++++++ .../wireless/mediatek/mt76/mt76x2/pci_phy.c | 30 ++----------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h index 1a20c1852dbf..3a5ba5d209ba 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h @@ -19,6 +19,32 @@ #include "mt76x02_regs.h" +static inline int +mt76x02_get_rssi_gain_thresh(struct mt76x02_dev *dev) +{ + switch (dev->mt76.chandef.width) { + case NL80211_CHAN_WIDTH_80: + return -62; + case NL80211_CHAN_WIDTH_40: + return -65; + default: + return -68; + } +} + +static inline int +mt76x02_get_low_rssi_gain_thresh(struct mt76x02_dev *dev) +{ + switch (dev->mt76.chandef.width) { + case NL80211_CHAN_WIDTH_80: + return -76; + case NL80211_CHAN_WIDTH_40: + return -79; + default: + return -82; + } +} + void mt76x02_add_rate_power_offset(struct mt76_rate_power *r, int offset); void mt76x02_phy_set_txpower(struct mt76x02_dev *dev, int txp_0, int txp_2); void mt76x02_limit_rate_power(struct mt76_rate_power *r, int limit); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c index 55708b8e6e10..86b87d896b46 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c @@ -131,32 +131,6 @@ mt76x2_get_agc_gain(struct mt76x02_dev *dev, u8 *dest) dest[1] = mt76_get_field(dev, MT_BBP(AGC, 9), MT_BBP_AGC_GAIN); } -static int -mt76x2_get_rssi_gain_thresh(struct mt76x02_dev *dev) -{ - switch (dev->mt76.chandef.width) { - case NL80211_CHAN_WIDTH_80: - return -62; - case NL80211_CHAN_WIDTH_40: - return -65; - default: - return -68; - } -} - -static int -mt76x2_get_low_rssi_gain_thresh(struct mt76x02_dev *dev) -{ - switch (dev->mt76.chandef.width) { - case NL80211_CHAN_WIDTH_80: - return -76; - case NL80211_CHAN_WIDTH_40: - return -79; - default: - return -82; - } -} - static void mt76x2_phy_set_gain_val(struct mt76x02_dev *dev) { @@ -212,8 +186,8 @@ mt76x2_phy_update_channel_gain(struct mt76x02_dev *dev) dev->cal.avg_rssi_all = mt76x02_phy_get_min_avg_rssi(dev); - low_gain = (dev->cal.avg_rssi_all > mt76x2_get_rssi_gain_thresh(dev)) + - (dev->cal.avg_rssi_all > mt76x2_get_low_rssi_gain_thresh(dev)); + low_gain = (dev->cal.avg_rssi_all > mt76x02_get_rssi_gain_thresh(dev)) + + (dev->cal.avg_rssi_all > mt76x02_get_low_rssi_gain_thresh(dev)); gain_change = (dev->cal.low_gain & 2) ^ (low_gain & 2); dev->cal.low_gain = low_gain; From patchwork Fri Oct 12 10:16:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638415 X-Patchwork-Delegate: kvalo@adurom.com 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 6A69B14E2 for ; Fri, 12 Oct 2018 10:16:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A5332B727 for ; Fri, 12 Oct 2018 10:16:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EB552B939; Fri, 12 Oct 2018 10:16: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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E025D2B727 for ; Fri, 12 Oct 2018 10:16:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728477AbeJLRsf (ORCPT ); Fri, 12 Oct 2018 13:48:35 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40234 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728447AbeJLRsd (ORCPT ); Fri, 12 Oct 2018 13:48:33 -0400 Received: by mail-wr1-f67.google.com with SMTP id d2-v6so12835670wro.7 for ; Fri, 12 Oct 2018 03:16:51 -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=9088u/jGIS6A7miZmt1wFY22zB47wMtCMBFuElZaetY=; b=tKfpbw18D1tq6UoSFyp4nL4dMeccmQvyaVVipqOBfsEUlMtyLxmiZE09VUvActXu1Q ES5+6OTmnfKhT5EOr5LNT+J5t7MakGP2C6/hWKScasqxLyDQ6P9SVJW/ll50dByb+DvT YazT434DyHVl0VPaJHgY1lNpqmiu0WPcDresNuTK9ypIh7MZDzrOO1XF4+5N7jcVM8FJ fIj1Kcb8ngW4wAU/7NtklF97OBCYjmcoJHWYz0a3QaN0K/2pr9Z3LG0Ois0ivQSK0vPe KLiGiPRSEZ+/7TT4IgvjBIN2A3VphG8eSyNJcONYWNLFHS0J6i6afdtnkZ/fO4G9dkJ2 gibA== X-Gm-Message-State: ABuFfohYX5JgrSNwLXtuzMulUGfIf0RL7pk1puDVSVDtHhCxk0sN1LvR UspPRmQfSpVD1pFQ41WjGj7FsA== X-Google-Smtp-Source: ACcGV61L6kpSxVLxcG0oAXeheo9OtQTg4Q4MH7WjYYSZrPsfink6OL1tj3VBYZY1/cp/4jTJfrybTg== X-Received: by 2002:adf:c405:: with SMTP id v5-v6mr5063294wrf.20.1539339410889; Fri, 12 Oct 2018 03:16:50 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:50 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 09/13] mt76: move mt76x02_phy_adjust_vga_gain in mt76/mt76x02_phy.c Date: Fri, 12 Oct 2018 12:16:25 +0200 Message-Id: <9aabe74ab0a0a5e553020ec5dcda75b05d189f90.1539338611.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move mt76x02_phy_adjust_vga_gain routine in mt76x02-lib module in order to be reused by mt76x0 driver for vga calibration Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x02_phy.c | 21 ++++++++++++++++++ .../net/wireless/mediatek/mt76/mt76x02_phy.h | 1 + .../wireless/mediatek/mt76/mt76x2/pci_phy.c | 22 ++----------------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c index b0c78ab97ad7..97310da37d77 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c @@ -223,3 +223,24 @@ void mt76x02_phy_set_band(struct mt76x02_dev *dev, int band, primary_upper); } EXPORT_SYMBOL_GPL(mt76x02_phy_set_band); + +bool mt76x02_phy_adjust_vga_gain(struct mt76x02_dev *dev) +{ + u8 limit = dev->cal.low_gain > 0 ? 16 : 4; + bool ret = false; + u32 false_cca; + + false_cca = FIELD_GET(MT_RX_STAT_1_CCA_ERRORS, mt76_rr(dev, MT_RX_STAT_1)); + dev->cal.false_cca = false_cca; + if (false_cca > 800 && dev->cal.agc_gain_adjust < limit) { + dev->cal.agc_gain_adjust += 2; + ret = true; + } else if ((false_cca < 10 && dev->cal.agc_gain_adjust > 0) || + (dev->cal.agc_gain_adjust >= limit && false_cca < 500)) { + dev->cal.agc_gain_adjust -= 2; + ret = true; + } + + return ret; +} +EXPORT_SYMBOL_GPL(mt76x02_phy_adjust_vga_gain); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h index 3a5ba5d209ba..8e3a0f93ca80 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h @@ -55,5 +55,6 @@ int mt76x02_phy_get_min_avg_rssi(struct mt76x02_dev *dev); void mt76x02_phy_set_bw(struct mt76x02_dev *dev, int width, u8 ctrl); void mt76x02_phy_set_band(struct mt76x02_dev *dev, int band, bool primary_upper); +bool mt76x02_phy_adjust_vga_gain(struct mt76x02_dev *dev); #endif /* __MT76x02_PHY_H */ diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c index 86b87d896b46..818d2f3e8ac9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c @@ -156,25 +156,6 @@ mt76x2_phy_set_gain_val(struct mt76x02_dev *dev) mt76x2_dfs_adjust_agc(dev); } -static void -mt76x2_phy_adjust_vga_gain(struct mt76x02_dev *dev) -{ - u32 false_cca; - u8 limit = dev->cal.low_gain > 0 ? 16 : 4; - - false_cca = FIELD_GET(MT_RX_STAT_1_CCA_ERRORS, mt76_rr(dev, MT_RX_STAT_1)); - dev->cal.false_cca = false_cca; - if (false_cca > 800 && dev->cal.agc_gain_adjust < limit) - dev->cal.agc_gain_adjust += 2; - else if ((false_cca < 10 && dev->cal.agc_gain_adjust > 0) || - (dev->cal.agc_gain_adjust >= limit && false_cca < 500)) - dev->cal.agc_gain_adjust -= 2; - else - return; - - mt76x2_phy_set_gain_val(dev); -} - static void mt76x2_phy_update_channel_gain(struct mt76x02_dev *dev) { @@ -193,7 +174,8 @@ mt76x2_phy_update_channel_gain(struct mt76x02_dev *dev) dev->cal.low_gain = low_gain; if (!gain_change) { - mt76x2_phy_adjust_vga_gain(dev); + if (mt76x02_phy_adjust_vga_gain(dev)) + mt76x2_phy_set_gain_val(dev); return; } From patchwork Fri Oct 12 10:16:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638411 X-Patchwork-Delegate: kvalo@adurom.com 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 31FB63CF1 for ; Fri, 12 Oct 2018 10:16:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20E192B727 for ; Fri, 12 Oct 2018 10:16:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1549A2B8FD; Fri, 12 Oct 2018 10:16:55 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC1BB2B727 for ; Fri, 12 Oct 2018 10:16:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728474AbeJLRse (ORCPT ); Fri, 12 Oct 2018 13:48:34 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39683 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728457AbeJLRse (ORCPT ); Fri, 12 Oct 2018 13:48:34 -0400 Received: by mail-wr1-f66.google.com with SMTP id 61-v6so12822656wrb.6 for ; Fri, 12 Oct 2018 03:16:52 -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=nGrpyvovGZTYcPfwMIBYxR6wfRO9iJ3V3oy9T78GfaA=; b=HArT2h1tK7MJRRJVbDlKP0PtVo1rnthFa+8CQPMBxIB87QnJ8ROKu+CbVbIgqzwnLg G0NpiedNbJNC6eoF6+dNYiDDnuWAew49DEPoVmvUoBosyvi3DKLFUb0lKfJKZ+U4fcJE ZJCioaIlyA7hn95j2fYYCoMND++zEGB/AVdyyeW3nBOR7qoQEBrlsyDLWTQKMF2XFFUA /KWBsWzRuSy8QtgISPyyHtJ9rGkrZKSFPGv/+SUAnZKYjKgbiYMF0Z9AdFeVoOrXShal kNhiOp7cj/4ZCkD7MUHe9myVmU18s/OF3qExHvZfmJNH6AwGjm7lAU7fDUasgda7qUYM IgHg== X-Gm-Message-State: ABuFfogaEYkqWcmT8g81oCOX/pdiEInX4VogwDXqP1RvIO2emtO2E3cS esTUzn3WWF4717xiAuvCmv35Aw== X-Google-Smtp-Source: ACcGV61fJ4GIYyeuV11d/KsgaXpKaVxTaOqqrBK7nuGWxeiG3ISBetkDWBsTXtULiw/xuNHiPwMuag== X-Received: by 2002:adf:93a5:: with SMTP id 34-v6mr4880451wrp.244.1539339411952; Fri, 12 Oct 2018 03:16:51 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:51 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 10/13] mt76: introduce mt76x02_init_agc_gain routine Date: Fri, 12 Oct 2018 12:16:26 +0200 Message-Id: <2a1e5f6ebd1d7a3ab35547d66e241b9f312b448e.1539338611.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add mt76x02_init_agc_gain routine in mt76x02-lib moudule in order to be reused by mt76x0 for vga initalization Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76x02_phy.c | 12 ++++++++++++ drivers/net/wireless/mediatek/mt76/mt76x02_phy.h | 1 + drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c | 12 +----------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c index 97310da37d77..0f1d7b5c9f68 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c @@ -244,3 +244,15 @@ bool mt76x02_phy_adjust_vga_gain(struct mt76x02_dev *dev) return ret; } EXPORT_SYMBOL_GPL(mt76x02_phy_adjust_vga_gain); + +void mt76x02_init_agc_gain(struct mt76x02_dev *dev) +{ + dev->cal.agc_gain_init[0] = mt76_get_field(dev, MT_BBP(AGC, 8), + MT_BBP_AGC_GAIN); + dev->cal.agc_gain_init[1] = mt76_get_field(dev, MT_BBP(AGC, 9), + MT_BBP_AGC_GAIN); + memcpy(dev->cal.agc_gain_cur, dev->cal.agc_gain_init, + sizeof(dev->cal.agc_gain_cur)); + dev->cal.low_gain = -1; +} +EXPORT_SYMBOL_GPL(mt76x02_init_agc_gain); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h index 8e3a0f93ca80..2b316cf7c70c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h @@ -56,5 +56,6 @@ void mt76x02_phy_set_bw(struct mt76x02_dev *dev, int width, u8 ctrl); void mt76x02_phy_set_band(struct mt76x02_dev *dev, int band, bool primary_upper); bool mt76x02_phy_adjust_vga_gain(struct mt76x02_dev *dev); +void mt76x02_init_agc_gain(struct mt76x02_dev *dev); #endif /* __MT76x02_PHY_H */ diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c index 818d2f3e8ac9..5bda44540225 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_phy.c @@ -124,13 +124,6 @@ void mt76x2_phy_set_antenna(struct mt76x02_dev *dev) mt76_wr(dev, MT_BBP(AGC, 0), val); } -static void -mt76x2_get_agc_gain(struct mt76x02_dev *dev, u8 *dest) -{ - dest[0] = mt76_get_field(dev, MT_BBP(AGC, 8), MT_BBP_AGC_GAIN); - dest[1] = mt76_get_field(dev, MT_BBP(AGC, 9), MT_BBP_AGC_GAIN); -} - static void mt76x2_phy_set_gain_val(struct mt76x02_dev *dev) { @@ -340,11 +333,8 @@ int mt76x2_phy_set_channel(struct mt76x02_dev *dev, if (scan) return 0; - dev->cal.low_gain = -1; mt76x2_phy_channel_calibrate(dev, true); - mt76x2_get_agc_gain(dev, dev->cal.agc_gain_init); - memcpy(dev->cal.agc_gain_cur, dev->cal.agc_gain_init, - sizeof(dev->cal.agc_gain_cur)); + mt76x02_init_agc_gain(dev); /* init default values for temp compensation */ if (mt76x2_tssi_enabled(dev)) { From patchwork Fri Oct 12 10:16:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638413 X-Patchwork-Delegate: kvalo@adurom.com 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 AD01114E2 for ; Fri, 12 Oct 2018 10:16:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CFC32B727 for ; Fri, 12 Oct 2018 10:16:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 911FF2B939; Fri, 12 Oct 2018 10:16:56 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A32A2B727 for ; Fri, 12 Oct 2018 10:16:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728483AbeJLRsg (ORCPT ); Fri, 12 Oct 2018 13:48:36 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:40250 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728366AbeJLRsf (ORCPT ); Fri, 12 Oct 2018 13:48:35 -0400 Received: by mail-wm1-f65.google.com with SMTP id z204-v6so12419252wmc.5 for ; Fri, 12 Oct 2018 03:16:53 -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=kjKB6H9HJ/zoIMHKpRNZavO57yiHcldgs3pURnwW1y4=; b=pnm/KJOfezyVMbajhF+1S8OcRNzPMCbzKht2/DBP3rBGYOFnltYZmdBkoLXwJ8LXRa y7GdNivejIlwAZgElaGayIUDA7ew+5Upyymc4USZlCo7fMgqyrsTUZ0vHjQc89vzB4b8 UZqzvnVtMlYVty2sLwLnFO9reCHUGg5OVpYdiNFG+IWdHxZO4K5D4tvsWEeJqt26KWuj NAzZsMzXoSeLO61a04VFb8GJUMmD3GgT6eNuTLJv7sK2Z/U5mUO8O8o7Kz80So2+w4Jz 6rW4tvirGtrSozICBsm5rDpzOqh/592skO9faDciK+9/qs1b2ndNVzzwYYF3nQ37dWh3 LHdA== X-Gm-Message-State: ABuFfohwAAOnZh7yI0NTBtYE2LFhy+iYG3+lxCkaREIrTd+W4csCoCv8 sea07NqoN4gMD9gvpvXvjHlApg== X-Google-Smtp-Source: ACcGV60rUXy7cv6TUpxtpOmN2O3e4Y+FHNVmcR6PTSO9BlU+wlkDXtYk8XtxPs1tFcfvqGjPgx0O6A== X-Received: by 2002:a1c:7e57:: with SMTP id z84-v6mr5014086wmc.43.1539339412943; Fri, 12 Oct 2018 03:16:52 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:52 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 11/13] mt76x0: phy: align channel gain logic to mt76x2 one Date: Fri, 12 Oct 2018 12:16:27 +0200 Message-Id: <0ac5553d54bce90cf9d466f3e53efc9edc558ab4.1539338611.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Update vga tuning algorithm to the one used in mt76x2 driver Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 7d29fd16342a..3d0fcf8c34b4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -719,6 +719,7 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, mt76x0_read_rx_gain(dev); mt76x0_phy_set_chan_bbp_params(dev, rf_bw_band); + mt76x02_init_agc_gain(dev); if (mt76_is_usb(dev)) { mt76x0_vco_cal(dev, channel); @@ -820,23 +821,44 @@ static void mt76x0_temp_sensor(struct mt76x02_dev *dev) rf_wr(dev, MT_RF(0, 67), rf_b0_67); } -static void mt76x0_dynamic_vga_tuning(struct mt76x02_dev *dev) +static void mt76x0_phy_set_gain_val(struct mt76x02_dev *dev) { - struct cfg80211_chan_def *chandef = &dev->mt76.chandef; - u32 val, init_vga; - int avg_rssi; - - init_vga = chandef->chan->band == NL80211_BAND_5GHZ ? 0x54 : 0x4E; - avg_rssi = mt76x02_phy_get_min_avg_rssi(dev); - if (avg_rssi > -60) - init_vga -= 0x20; - else if (avg_rssi > -70) - init_vga -= 0x10; - - val = mt76_rr(dev, MT_BBP(AGC, 8)); - val &= 0xFFFF80FF; - val |= init_vga << 8; - mt76_wr(dev, MT_BBP(AGC,8), val); + u8 gain = dev->cal.agc_gain_cur[0] - dev->cal.agc_gain_adjust; + u32 val = 0x122c << 16 | 0xf2; + + mt76_wr(dev, MT_BBP(AGC, 8), + val | FIELD_PREP(MT_BBP_AGC_GAIN, gain)); +} + +static void +mt76x0_phy_update_channel_gain(struct mt76x02_dev *dev) +{ + bool gain_change; + u8 gain_delta; + int low_gain; + + dev->cal.avg_rssi_all = mt76x02_phy_get_min_avg_rssi(dev); + + low_gain = (dev->cal.avg_rssi_all > mt76x02_get_rssi_gain_thresh(dev)) + + (dev->cal.avg_rssi_all > mt76x02_get_low_rssi_gain_thresh(dev)); + + gain_change = (dev->cal.low_gain & 2) ^ (low_gain & 2); + dev->cal.low_gain = low_gain; + + if (!gain_change) { + if (mt76x02_phy_adjust_vga_gain(dev)) + mt76x0_phy_set_gain_val(dev); + return; + } + + dev->cal.agc_gain_adjust = (low_gain == 2) ? 0 : 10; + gain_delta = (low_gain == 2) ? 10 : 0; + + dev->cal.agc_gain_cur[0] = dev->cal.agc_gain_init[0] - gain_delta; + mt76x0_phy_set_gain_val(dev); + + /* clear false CCA counters */ + mt76_rr(dev, MT_RX_STAT_1); } static void mt76x0_phy_calibration_work(struct work_struct *work) @@ -844,7 +866,7 @@ static void mt76x0_phy_calibration_work(struct work_struct *work) struct mt76x02_dev *dev = container_of(work, struct mt76x02_dev, cal_work.work); - mt76x0_dynamic_vga_tuning(dev); + mt76x0_phy_update_channel_gain(dev); if (!mt76x0_tssi_enabled(dev)) mt76x0_temp_sensor(dev); From patchwork Fri Oct 12 10:16:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638417 X-Patchwork-Delegate: kvalo@adurom.com 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 076BA157A for ; Fri, 12 Oct 2018 10:16:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA6882B727 for ; Fri, 12 Oct 2018 10:16:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEF412B8FD; Fri, 12 Oct 2018 10:16:58 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71D352B727 for ; Fri, 12 Oct 2018 10:16:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728486AbeJLRsi (ORCPT ); Fri, 12 Oct 2018 13:48:38 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52367 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728457AbeJLRsh (ORCPT ); Fri, 12 Oct 2018 13:48:37 -0400 Received: by mail-wm1-f67.google.com with SMTP id 189-v6so11769475wmw.2 for ; Fri, 12 Oct 2018 03:16:54 -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=kZxyi2P2T3uYGSMsGiGwHxzqrWPRNEx5ThQrzVMbffw=; b=HvJ6duAZOZQwwTRcf9uYka2A2qEYtmMmKlKTngIJr9h6X/MeKYBz109UY4mxJzr1gT 8517U+MDYwY8eWvykA73lv2e1eiiyh/eAum2ADRs7p2kojZ6xjAXw/II8hnf6sq2U6E7 ejDz2tcz+xg/6E7dhRqMSnB56Jh073y5CEOE/KIDoLHF1zFsMLTeRVrdKPDl4B+RZ0dD /yFPf+eqr6cLm8XexIQhvu89XcZpIfBPIyJn62xgALknq9n8A+rBzMsLPUU6LIQOI6pU 2/UZOm306cc7dpr8YyqEjxIIff7IDPNvtLT9AJrsFZhrmyFJDRZV+30hbbMoSL7iKdIK 0LLg== X-Gm-Message-State: ABuFfohaBS8+OgDeGV1cMsMP7WIKU+9jDg5CbfD8Ay9QOVX6+HNaXKIC snVRK35oTAUOyM+E6T+88VSvqQ== X-Google-Smtp-Source: ACcGV61i10jyU0hPlXtkn89/VO8+SEDe8tSvD+QLqvEh8nFZ4qdO2hoZBlz1TIL0hX6S7vjQfwfCVQ== X-Received: by 2002:a1c:448a:: with SMTP id r132-v6mr4792430wma.132.1539339413942; Fri, 12 Oct 2018 03:16:53 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:53 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 12/13] mt76x0: phy: do not run calibration during channel switch Date: Fri, 12 Oct 2018 12:16:28 +0200 Message-Id: X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Do not perform phy/vga calibration during channel switch. Moreover remove mt76x0_agc_save and mt76x0_agc_restore routines since they are no longer necessary. Furthermore run mt76_set_channel in order to check if there are pending frames during channel switch Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/main.c | 22 ++++++++++++------ .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 2 -- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 23 +++++++------------ drivers/net/wireless/mediatek/mt76/mt76x02.h | 2 -- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c index c9cd0254a979..9273d2d2764a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c @@ -16,6 +16,20 @@ #include #include "mt76x0.h" +static int +mt76x0_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef) +{ + int ret; + + cancel_delayed_work_sync(&dev->cal_work); + + mt76_set_channel(&dev->mt76); + ret = mt76x0_phy_set_channel(dev, chandef); + mt76_txq_schedule_all(&dev->mt76); + + return ret; +} + int mt76x0_config(struct ieee80211_hw *hw, u32 changed) { struct mt76x02_dev *dev = hw->priv; @@ -25,7 +39,7 @@ int mt76x0_config(struct ieee80211_hw *hw, u32 changed) if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { ieee80211_stop_queues(hw); - ret = mt76x0_phy_set_channel(dev, &hw->conf.chandef); + ret = mt76x0_set_channel(dev, &hw->conf.chandef); ieee80211_wake_queues(hw); } @@ -114,8 +128,6 @@ void mt76x0_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, { struct mt76x02_dev *dev = hw->priv; - cancel_delayed_work_sync(&dev->cal_work); - mt76x0_agc_save(dev); set_bit(MT76_SCANNING, &dev->mt76.state); } EXPORT_SYMBOL_GPL(mt76x0_sw_scan); @@ -125,11 +137,7 @@ void mt76x0_sw_scan_complete(struct ieee80211_hw *hw, { struct mt76x02_dev *dev = hw->priv; - mt76x0_agc_restore(dev); clear_bit(MT76_SCANNING, &dev->mt76.state); - - ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, - MT_CALIBRATE_INTERVAL); } EXPORT_SYMBOL_GPL(mt76x0_sw_scan_complete); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index 6717d83e0ff6..2187bafaf2e9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -66,8 +66,6 @@ int mt76x0_set_rts_threshold(struct ieee80211_hw *hw, u32 value); /* PHY */ void mt76x0_phy_init(struct mt76x02_dev *dev); int mt76x0_wait_bbp_ready(struct mt76x02_dev *dev); -void mt76x0_agc_save(struct mt76x02_dev *dev); -void mt76x0_agc_restore(struct mt76x02_dev *dev); int mt76x0_phy_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef); void mt76x0_phy_recalibrate_after_assoc(struct mt76x02_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 3d0fcf8c34b4..cf024950e0ed 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -723,17 +723,21 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, if (mt76_is_usb(dev)) { mt76x0_vco_cal(dev, channel); - if (scan) - mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1, - false); } else { /* enable vco */ rf_set(dev, MT_RF(0, 4), BIT(7)); - mt76x0_phy_calibrate(dev, false); } + if (scan) + return 0; + + if (mt76_is_mmio(dev)) + mt76x0_phy_calibrate(dev, false); mt76x0_phy_set_txpower(dev); + ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, + MT_CALIBRATE_INTERVAL); + return 0; } @@ -770,17 +774,6 @@ void mt76x0_phy_recalibrate_after_assoc(struct mt76x02_dev *dev) mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1, false); } -void mt76x0_agc_save(struct mt76x02_dev *dev) -{ - /* Only one RX path */ - dev->agc_save = FIELD_GET(MT_BBP_AGC_GAIN, mt76_rr(dev, MT_BBP(AGC, 8))); -} - -void mt76x0_agc_restore(struct mt76x02_dev *dev) -{ - mt76_rmw_field(dev, MT_BBP(AGC, 8), MT_BBP_AGC_GAIN, dev->agc_save); -} - static void mt76x0_temp_sensor(struct mt76x02_dev *dev) { u8 rf_b7_73, rf_b0_66, rf_b0_67; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02.h b/drivers/net/wireless/mediatek/mt76/mt76x02.h index f375fdcbd2bf..47c42c607964 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02.h @@ -102,8 +102,6 @@ struct mt76x02_dev { bool no_2ghz; - u8 agc_save; - u8 coverage_class; u8 slottime; From patchwork Fri Oct 12 10:16:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10638419 X-Patchwork-Delegate: kvalo@adurom.com 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 4EBD4157A for ; Fri, 12 Oct 2018 10:17:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D1432B727 for ; Fri, 12 Oct 2018 10:17:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 316B72B930; Fri, 12 Oct 2018 10:17:01 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB4442B727 for ; Fri, 12 Oct 2018 10:16:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728491AbeJLRsj (ORCPT ); Fri, 12 Oct 2018 13:48:39 -0400 Received: from mail-wr1-f46.google.com ([209.85.221.46]:40401 "EHLO mail-wr1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728366AbeJLRsj (ORCPT ); Fri, 12 Oct 2018 13:48:39 -0400 Received: by mail-wr1-f46.google.com with SMTP id d2-v6so12835955wro.7 for ; Fri, 12 Oct 2018 03:16:55 -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=WRZioZmLQJ8yDPrlF3fUpkqeC1wQfchYa5g9i18pFVM=; b=q3kwsm1oKwPYt7T1sHB14Q3FyViEARGREM6YSOqevweFfhSrSe171DugH8Z2Wuu1Tw Gq/DVtE9I+epCTAQHDniea2pg0aR3YMkf+iWG8oAfebbStAoHPWIHPs+DRhtTixlpPP6 CA8RXiuUeLMwk0s4EvyAbPOWya62y6zyLDpIn03C/1EWCrsSL5InHrL7xthREdqetYjP mU0/PEujjnjNincH1pyJre3DU4qGfaZmsHSPYbhX8XSp9ge3LPqmtb34RdprTm8FQEQn TmZk2UGNqhPdQr6TXV0dPaLbs2OkI4hayl27BfwtsvSTzfsObqM8HKzLelj6Q2TJpJ16 ylug== X-Gm-Message-State: ABuFfohopaw1j3oZ2N/oMSypwHxLmH0ErnzvAIhyxdURLAtpi5mdvGHv F1DZWaHVjgQ1O3NJaRBrYAVwCQ== X-Google-Smtp-Source: ACcGV60+Vc9HH+7xmX2rQXlE74zZ5TRPv47tmsD/yMteuSBPWx2U8V+GICxuEm8NxWqOJduCtiZkng== X-Received: by 2002:a5d:6511:: with SMTP id x17-v6mr4944601wru.150.1539339414975; Fri, 12 Oct 2018 03:16:54 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id r2-v6sm473179wrq.1.2018.10.12.03.16.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Oct 2018 03:16:54 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 13/13] mt76x0: phy: use proper name convention Date: Fri, 12 Oct 2018 12:16:29 +0200 Message-Id: <77e1a64480cbcf20b335f3ae6c7427d797d71853.1539338611.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use mt76x0_phy as prefix for routines in mt76x0/phy.c Moreover use mt76x0_phy_rf_set to enable vco calibration in mt76x0_phy_vco_cal Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/init.c | 2 +- .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 2 +- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 228 +++++++++--------- 3 files changed, 117 insertions(+), 115 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c index 578f1b34f0f1..ac7a949801fb 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/init.c @@ -113,7 +113,7 @@ static int mt76x0_init_bbp(struct mt76x02_dev *dev) { int ret, i; - ret = mt76x0_wait_bbp_ready(dev); + ret = mt76x0_phy_wait_bbp_ready(dev); if (ret) return ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index 2187bafaf2e9..f27335ccb582 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -65,7 +65,7 @@ int mt76x0_set_rts_threshold(struct ieee80211_hw *hw, u32 value); /* PHY */ void mt76x0_phy_init(struct mt76x02_dev *dev); -int mt76x0_wait_bbp_ready(struct mt76x02_dev *dev); +int mt76x0_phy_wait_bbp_ready(struct mt76x02_dev *dev); int mt76x0_phy_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef); void mt76x0_phy_recalibrate_after_assoc(struct mt76x02_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index cf024950e0ed..79408a44980b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -27,7 +27,7 @@ #include "../mt76x02_phy.h" static int -mt76x0_rf_csr_wr(struct mt76x02_dev *dev, u32 offset, u8 value) +mt76x0_phy_rf_csr_wr(struct mt76x02_dev *dev, u32 offset, u8 value) { int ret = 0; u8 bank, reg; @@ -65,7 +65,8 @@ mt76x0_rf_csr_wr(struct mt76x02_dev *dev, u32 offset, u8 value) return ret; } -static int mt76x0_rf_csr_rr(struct mt76x02_dev *dev, u32 offset) +static int +mt76x0_phy_rf_csr_rr(struct mt76x02_dev *dev, u32 offset) { int ret = -ETIMEDOUT; u32 val; @@ -110,7 +111,7 @@ static int mt76x0_rf_csr_rr(struct mt76x02_dev *dev, u32 offset) } static int -rf_wr(struct mt76x02_dev *dev, u32 offset, u8 val) +mt76x0_phy_rf_wr(struct mt76x02_dev *dev, u32 offset, u8 val) { if (mt76_is_usb(dev)) { struct mt76_reg_pair pair = { @@ -122,12 +123,11 @@ rf_wr(struct mt76x02_dev *dev, u32 offset, u8 val) &dev->mt76.state)); return mt76_wr_rp(dev, MT_MCU_MEMMAP_RF, &pair, 1); } else { - return mt76x0_rf_csr_wr(dev, offset, val); + return mt76x0_phy_rf_csr_wr(dev, offset, val); } } -static int -rf_rr(struct mt76x02_dev *dev, u32 offset) +static int mt76x0_phy_rf_rr(struct mt76x02_dev *dev, u32 offset) { int ret; u32 val; @@ -142,22 +142,22 @@ rf_rr(struct mt76x02_dev *dev, u32 offset) ret = mt76_rd_rp(dev, MT_MCU_MEMMAP_RF, &pair, 1); val = pair.value; } else { - ret = val = mt76x0_rf_csr_rr(dev, offset); + ret = val = mt76x0_phy_rf_csr_rr(dev, offset); } return (ret < 0) ? ret : val; } static int -rf_rmw(struct mt76x02_dev *dev, u32 offset, u8 mask, u8 val) +mt76x0_phy_rf_rmw(struct mt76x02_dev *dev, u32 offset, u8 mask, u8 val) { int ret; - ret = rf_rr(dev, offset); + ret = mt76x0_phy_rf_rr(dev, offset); if (ret < 0) return ret; val |= ret & ~mask; - ret = rf_wr(dev, offset, val); + ret = mt76x0_phy_rf_wr(dev, offset, val); if (ret) return ret; @@ -165,37 +165,38 @@ rf_rmw(struct mt76x02_dev *dev, u32 offset, u8 mask, u8 val) } static int -rf_set(struct mt76x02_dev *dev, u32 offset, u8 val) +mt76x0_phy_rf_set(struct mt76x02_dev *dev, u32 offset, u8 val) { - return rf_rmw(dev, offset, 0, val); + return mt76x0_phy_rf_rmw(dev, offset, 0, val); } #if 0 static int rf_clear(struct mt76x02_dev *dev, u32 offset, u8 mask) { - return rf_rmw(dev, offset, mask, 0); + return mt76x0_phy_rf_rmw(dev, offset, mask, 0); } #endif static void -mt76x0_rf_csr_wr_rp(struct mt76x02_dev *dev, const struct mt76_reg_pair *data, - int n) +mt76x0_phy_rf_csr_wr_rp(struct mt76x02_dev *dev, + const struct mt76_reg_pair *data, + int n) { while (n-- > 0) { - mt76x0_rf_csr_wr(dev, data->reg, data->value); + mt76x0_phy_rf_csr_wr(dev, data->reg, data->value); data++; } } #define RF_RANDOM_WRITE(dev, tab) do { \ if (mt76_is_mmio(dev)) \ - mt76x0_rf_csr_wr_rp(dev, tab, ARRAY_SIZE(tab)); \ + mt76x0_phy_rf_csr_wr_rp(dev, tab, ARRAY_SIZE(tab)); \ else \ mt76_wr_rp(dev, MT_MCU_MEMMAP_RF, tab, ARRAY_SIZE(tab));\ } while (0) -int mt76x0_wait_bbp_ready(struct mt76x02_dev *dev) +int mt76x0_phy_wait_bbp_ready(struct mt76x02_dev *dev) { int i = 20; u32 val; @@ -215,11 +216,11 @@ int mt76x0_wait_bbp_ready(struct mt76x02_dev *dev) return 0; } -static void mt76x0_vco_cal(struct mt76x02_dev *dev, u8 channel) +static void mt76x0_phy_vco_cal(struct mt76x02_dev *dev, u8 channel) { u8 val; - val = rf_rr(dev, MT_RF(0, 4)); + val = mt76x0_phy_rf_rr(dev, MT_RF(0, 4)); if ((val & 0x70) != 0x30) return; @@ -235,20 +236,20 @@ static void mt76x0_vco_cal(struct mt76x02_dev *dev, u8 channel) * 40MHz channel: 101 * 20MHz channel: 100 */ - val = rf_rr(dev, MT_RF(0, 6)); + val = mt76x0_phy_rf_rr(dev, MT_RF(0, 6)); val &= ~0xf; val |= 0x09; - rf_wr(dev, MT_RF(0, 6), val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 6), val); - val = rf_rr(dev, MT_RF(0, 5)); + val = mt76x0_phy_rf_rr(dev, MT_RF(0, 5)); if (val != 0) - rf_wr(dev, MT_RF(0, 5), 0x0); + mt76x0_phy_rf_wr(dev, MT_RF(0, 5), 0x0); - val = rf_rr(dev, MT_RF(0, 4)); + val = mt76x0_phy_rf_rr(dev, MT_RF(0, 4)); val &= ~0x07; - rf_wr(dev, MT_RF(0, 4), val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 4), val); - val = rf_rr(dev, MT_RF(0, 3)); + val = mt76x0_phy_rf_rr(dev, MT_RF(0, 3)); val &= ~0x77; if (channel == 1 || channel == 7 || channel == 9 || channel >= 13) { val |= 0x63; @@ -261,12 +262,9 @@ static void mt76x0_vco_cal(struct mt76x02_dev *dev, u8 channel) WARN(1, "Unknown channel %u\n", channel); return; } - rf_wr(dev, MT_RF(0, 3), val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 3), val); - /* TODO replace by mt76x0_rf_set(dev, MT_RF(0, 4), BIT(7)); */ - val = rf_rr(dev, MT_RF(0, 4)); - val = ((val & ~(0x80)) | 0x80); - rf_wr(dev, MT_RF(0, 4), val); + mt76x0_phy_rf_set(dev, MT_RF(0, 4), BIT(7)); msleep(2); } @@ -278,8 +276,8 @@ mt76x0_phy_set_band(struct mt76x02_dev *dev, enum nl80211_band band) case NL80211_BAND_2GHZ: RF_RANDOM_WRITE(dev, mt76x0_rf_2g_channel_0_tab); - rf_wr(dev, MT_RF(5, 0), 0x45); - rf_wr(dev, MT_RF(6, 0), 0x44); + mt76x0_phy_rf_wr(dev, MT_RF(5, 0), 0x45); + mt76x0_phy_rf_wr(dev, MT_RF(6, 0), 0x44); mt76_wr(dev, MT_TX_ALC_VGA3, 0x00050007); mt76_wr(dev, MT_TX0_RF_GAIN_CORR, 0x003E0002); @@ -287,8 +285,8 @@ mt76x0_phy_set_band(struct mt76x02_dev *dev, enum nl80211_band band) case NL80211_BAND_5GHZ: RF_RANDOM_WRITE(dev, mt76x0_rf_5g_channel_0_tab); - rf_wr(dev, MT_RF(5, 0), 0x44); - rf_wr(dev, MT_RF(6, 0), 0x45); + mt76x0_phy_rf_wr(dev, MT_RF(5, 0), 0x44); + mt76x0_phy_rf_wr(dev, MT_RF(6, 0), 0x45); mt76_wr(dev, MT_TX_ALC_VGA3, 0x00000005); mt76_wr(dev, MT_TX0_RF_GAIN_CORR, 0x01010102); @@ -326,103 +324,103 @@ mt76x0_phy_set_chan_rf_params(struct mt76x02_dev *dev, u8 channel, u16 rf_bw_ban else freq_item = &(mt76x0_frequency_plan[i]); - rf_wr(dev, MT_RF(0, 37), freq_item->pllR37); - rf_wr(dev, MT_RF(0, 36), freq_item->pllR36); - rf_wr(dev, MT_RF(0, 35), freq_item->pllR35); - rf_wr(dev, MT_RF(0, 34), freq_item->pllR34); - rf_wr(dev, MT_RF(0, 33), freq_item->pllR33); + mt76x0_phy_rf_wr(dev, MT_RF(0, 37), freq_item->pllR37); + mt76x0_phy_rf_wr(dev, MT_RF(0, 36), freq_item->pllR36); + mt76x0_phy_rf_wr(dev, MT_RF(0, 35), freq_item->pllR35); + mt76x0_phy_rf_wr(dev, MT_RF(0, 34), freq_item->pllR34); + mt76x0_phy_rf_wr(dev, MT_RF(0, 33), freq_item->pllR33); - rf_val = rf_rr(dev, MT_RF(0, 32)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 32)); rf_val &= ~0xE0; rf_val |= freq_item->pllR32_b7b5; - rf_wr(dev, MT_RF(0, 32), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 32), rf_val); /* R32<4:0> pll_den: (Denomina - 8) */ - rf_val = rf_rr(dev, MT_RF(0, 32)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 32)); rf_val &= ~0x1F; rf_val |= freq_item->pllR32_b4b0; - rf_wr(dev, MT_RF(0, 32), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 32), rf_val); /* R31<7:5> */ - rf_val = rf_rr(dev, MT_RF(0, 31)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 31)); rf_val &= ~0xE0; rf_val |= freq_item->pllR31_b7b5; - rf_wr(dev, MT_RF(0, 31), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 31), rf_val); /* R31<4:0> pll_k(Nominator) */ - rf_val = rf_rr(dev, MT_RF(0, 31)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 31)); rf_val &= ~0x1F; rf_val |= freq_item->pllR31_b4b0; - rf_wr(dev, MT_RF(0, 31), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 31), rf_val); /* R30<7> sdm_reset_n */ - rf_val = rf_rr(dev, MT_RF(0, 30)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 30)); rf_val &= ~0x80; if (bSDM) { - rf_wr(dev, MT_RF(0, 30), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 30), rf_val); rf_val |= 0x80; - rf_wr(dev, MT_RF(0, 30), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 30), rf_val); } else { rf_val |= freq_item->pllR30_b7; - rf_wr(dev, MT_RF(0, 30), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 30), rf_val); } /* R30<6:2> sdmmash_prbs,sin */ - rf_val = rf_rr(dev, MT_RF(0, 30)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 30)); rf_val &= ~0x7C; rf_val |= freq_item->pllR30_b6b2; - rf_wr(dev, MT_RF(0, 30), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 30), rf_val); /* R30<1> sdm_bp */ - rf_val = rf_rr(dev, MT_RF(0, 30)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 30)); rf_val &= ~0x02; rf_val |= (freq_item->pllR30_b1 << 1); - rf_wr(dev, MT_RF(0, 30), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 30), rf_val); /* R30<0> R29<7:0> (hex) pll_n */ rf_val = freq_item->pll_n & 0x00FF; - rf_wr(dev, MT_RF(0, 29), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 29), rf_val); - rf_val = rf_rr(dev, MT_RF(0, 30)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 30)); rf_val &= ~0x1; rf_val |= ((freq_item->pll_n >> 8) & 0x0001); - rf_wr(dev, MT_RF(0, 30), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 30), rf_val); /* R28<7:6> isi_iso */ - rf_val = rf_rr(dev, MT_RF(0, 28)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 28)); rf_val &= ~0xC0; rf_val |= freq_item->pllR28_b7b6; - rf_wr(dev, MT_RF(0, 28), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 28), rf_val); /* R28<5:4> pfd_dly */ - rf_val = rf_rr(dev, MT_RF(0, 28)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 28)); rf_val &= ~0x30; rf_val |= freq_item->pllR28_b5b4; - rf_wr(dev, MT_RF(0, 28), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 28), rf_val); /* R28<3:2> clksel option */ - rf_val = rf_rr(dev, MT_RF(0, 28)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 28)); rf_val &= ~0x0C; rf_val |= freq_item->pllR28_b3b2; - rf_wr(dev, MT_RF(0, 28), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 28), rf_val); /* R28<1:0> R27<7:0> R26<7:0> (hex) sdm_k */ rf_val = freq_item->pll_sdm_k & 0x000000FF; - rf_wr(dev, MT_RF(0, 26), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 26), rf_val); rf_val = ((freq_item->pll_sdm_k >> 8) & 0x000000FF); - rf_wr(dev, MT_RF(0, 27), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 27), rf_val); - rf_val = rf_rr(dev, MT_RF(0, 28)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 28)); rf_val &= ~0x3; rf_val |= ((freq_item->pll_sdm_k >> 16) & 0x0003); - rf_wr(dev, MT_RF(0, 28), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 28), rf_val); /* R24<1:0> xo_div */ - rf_val = rf_rr(dev, MT_RF(0, 24)); + rf_val = mt76x0_phy_rf_rr(dev, MT_RF(0, 24)); rf_val &= ~0x3; rf_val |= freq_item->pllR24_b1b0; - rf_wr(dev, MT_RF(0, 24), rf_val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 24), rf_val); break; } @@ -430,19 +428,22 @@ mt76x0_phy_set_chan_rf_params(struct mt76x02_dev *dev, u8 channel, u16 rf_bw_ban for (i = 0; i < ARRAY_SIZE(mt76x0_rf_bw_switch_tab); i++) { if (rf_bw == mt76x0_rf_bw_switch_tab[i].bw_band) { - rf_wr(dev, mt76x0_rf_bw_switch_tab[i].rf_bank_reg, - mt76x0_rf_bw_switch_tab[i].value); + mt76x0_phy_rf_wr(dev, + mt76x0_rf_bw_switch_tab[i].rf_bank_reg, + mt76x0_rf_bw_switch_tab[i].value); } else if ((rf_bw == (mt76x0_rf_bw_switch_tab[i].bw_band & 0xFF)) && (rf_band & mt76x0_rf_bw_switch_tab[i].bw_band)) { - rf_wr(dev, mt76x0_rf_bw_switch_tab[i].rf_bank_reg, - mt76x0_rf_bw_switch_tab[i].value); + mt76x0_phy_rf_wr(dev, + mt76x0_rf_bw_switch_tab[i].rf_bank_reg, + mt76x0_rf_bw_switch_tab[i].value); } } for (i = 0; i < ARRAY_SIZE(mt76x0_rf_band_switch_tab); i++) { if (mt76x0_rf_band_switch_tab[i].bw_band & rf_band) { - rf_wr(dev, mt76x0_rf_band_switch_tab[i].rf_bank_reg, - mt76x0_rf_band_switch_tab[i].value); + mt76x0_phy_rf_wr(dev, + mt76x0_rf_band_switch_tab[i].rf_bank_reg, + mt76x0_rf_band_switch_tab[i].value); } } @@ -470,8 +471,9 @@ mt76x0_phy_set_chan_rf_params(struct mt76x02_dev *dev, u8 channel, u16 rf_bw_ban /* External PA */ for (i = 0; i < ARRAY_SIZE(mt76x0_rf_ext_pa_tab); i++) if (mt76x0_rf_ext_pa_tab[i].bw_band & rf_band) - rf_wr(dev, mt76x0_rf_ext_pa_tab[i].rf_bank_reg, - mt76x0_rf_ext_pa_tab[i].value); + mt76x0_phy_rf_wr(dev, + mt76x0_rf_ext_pa_tab[i].rf_bank_reg, + mt76x0_rf_ext_pa_tab[i].value); } if (rf_band & RF_G_BAND) { @@ -516,7 +518,7 @@ mt76x0_phy_set_chan_bbp_params(struct mt76x02_dev *dev, u16 rf_bw_band) } } -static void mt76x0_ant_select(struct mt76x02_dev *dev) +static void mt76x0_phy_ant_select(struct mt76x02_dev *dev) { struct ieee80211_channel *chan = dev->mt76.chandef.chan; @@ -536,7 +538,7 @@ static void mt76x0_ant_select(struct mt76x02_dev *dev) } static void -mt76x0_bbp_set_bw(struct mt76x02_dev *dev, enum nl80211_chan_width width) +mt76x0_phy_bbp_set_bw(struct mt76x02_dev *dev, enum nl80211_chan_width width) { enum { BW_20 = 0, BW_40 = 1, BW_80 = 2, BW_10 = 4}; int bw; @@ -684,7 +686,7 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, } if (mt76_is_usb(dev)) { - mt76x0_bbp_set_bw(dev, chandef->width); + mt76x0_phy_bbp_set_bw(dev, chandef->width); } else { if (chandef->width == NL80211_CHAN_WIDTH_80 || chandef->width == NL80211_CHAN_WIDTH_40) @@ -696,7 +698,7 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, mt76x02_phy_set_bw(dev, chandef->width, ch_group_index); mt76x02_phy_set_band(dev, chandef->chan->band, ch_group_index & 1); - mt76x0_ant_select(dev); + mt76x0_phy_ant_select(dev); mt76_rmw(dev, MT_EXT_CCA_CFG, (MT_EXT_CCA_CFG_CCA0 | @@ -722,10 +724,10 @@ int mt76x0_phy_set_channel(struct mt76x02_dev *dev, mt76x02_init_agc_gain(dev); if (mt76_is_usb(dev)) { - mt76x0_vco_cal(dev, channel); + mt76x0_phy_vco_cal(dev, channel); } else { /* enable vco */ - rf_set(dev, MT_RF(0, 4), BIT(7)); + mt76x0_phy_rf_set(dev, MT_RF(0, 4), BIT(7)); } if (scan) @@ -749,7 +751,7 @@ void mt76x0_phy_recalibrate_after_assoc(struct mt76x02_dev *dev) mt76x02_mcu_calibrate(dev, MCU_CAL_R, 0, false); - mt76x0_vco_cal(dev, channel); + mt76x0_phy_vco_cal(dev, channel); tx_alc = mt76_rr(dev, MT_TX_ALC_CFG_0); mt76_wr(dev, MT_TX_ALC_CFG_0, 0); @@ -774,18 +776,18 @@ void mt76x0_phy_recalibrate_after_assoc(struct mt76x02_dev *dev) mt76x02_mcu_calibrate(dev, MCU_CAL_RXDCOC, 1, false); } -static void mt76x0_temp_sensor(struct mt76x02_dev *dev) +static void mt76x0_phy_temp_sensor(struct mt76x02_dev *dev) { u8 rf_b7_73, rf_b0_66, rf_b0_67; s8 val; - rf_b7_73 = rf_rr(dev, MT_RF(7, 73)); - rf_b0_66 = rf_rr(dev, MT_RF(0, 66)); - rf_b0_67 = rf_rr(dev, MT_RF(0, 67)); + rf_b7_73 = mt76x0_phy_rf_rr(dev, MT_RF(7, 73)); + rf_b0_66 = mt76x0_phy_rf_rr(dev, MT_RF(0, 66)); + rf_b0_67 = mt76x0_phy_rf_rr(dev, MT_RF(0, 67)); - rf_wr(dev, MT_RF(7, 73), 0x02); - rf_wr(dev, MT_RF(0, 66), 0x23); - rf_wr(dev, MT_RF(0, 67), 0x01); + mt76x0_phy_rf_wr(dev, MT_RF(7, 73), 0x02); + mt76x0_phy_rf_wr(dev, MT_RF(0, 66), 0x23); + mt76x0_phy_rf_wr(dev, MT_RF(0, 67), 0x01); mt76_wr(dev, MT_BBP(CORE, 34), 0x00080055); @@ -809,9 +811,9 @@ static void mt76x0_temp_sensor(struct mt76x02_dev *dev) } done: - rf_wr(dev, MT_RF(7, 73), rf_b7_73); - rf_wr(dev, MT_RF(0, 66), rf_b0_66); - rf_wr(dev, MT_RF(0, 67), rf_b0_67); + mt76x0_phy_rf_wr(dev, MT_RF(7, 73), rf_b7_73); + mt76x0_phy_rf_wr(dev, MT_RF(0, 66), rf_b0_66); + mt76x0_phy_rf_wr(dev, MT_RF(0, 67), rf_b0_67); } static void mt76x0_phy_set_gain_val(struct mt76x02_dev *dev) @@ -861,13 +863,13 @@ static void mt76x0_phy_calibration_work(struct work_struct *work) mt76x0_phy_update_channel_gain(dev); if (!mt76x0_tssi_enabled(dev)) - mt76x0_temp_sensor(dev); + mt76x0_phy_temp_sensor(dev); ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, MT_CALIBRATE_INTERVAL); } -static void mt76x0_rf_init(struct mt76x02_dev *dev) +static void mt76x0_phy_rf_init(struct mt76x02_dev *dev) { int i; u8 val; @@ -881,16 +883,16 @@ static void mt76x0_rf_init(struct mt76x02_dev *dev) const struct mt76x0_rf_switch_item *item = &mt76x0_rf_bw_switch_tab[i]; if (item->bw_band == RF_BW_20) - rf_wr(dev, item->rf_bank_reg, item->value); + mt76x0_phy_rf_wr(dev, item->rf_bank_reg, item->value); else if (((RF_G_BAND | RF_BW_20) & item->bw_band) == (RF_G_BAND | RF_BW_20)) - rf_wr(dev, item->rf_bank_reg, item->value); + mt76x0_phy_rf_wr(dev, item->rf_bank_reg, item->value); } for (i = 0; i < ARRAY_SIZE(mt76x0_rf_band_switch_tab); i++) { if (mt76x0_rf_band_switch_tab[i].bw_band & RF_G_BAND) { - rf_wr(dev, - mt76x0_rf_band_switch_tab[i].rf_bank_reg, - mt76x0_rf_band_switch_tab[i].value); + mt76x0_phy_rf_wr(dev, + mt76x0_rf_band_switch_tab[i].rf_bank_reg, + mt76x0_rf_band_switch_tab[i].value); } } @@ -899,32 +901,32 @@ static void mt76x0_rf_init(struct mt76x02_dev *dev) E1: B0.R22<6:0>: xo_cxo<6:0> E2: B0.R21<0>: xo_cxo<0>, B0.R22<7:0>: xo_cxo<8:1> */ - rf_wr(dev, MT_RF(0, 22), - min_t(u8, dev->cal.rx.freq_offset, 0xbf)); - val = rf_rr(dev, MT_RF(0, 22)); + mt76x0_phy_rf_wr(dev, MT_RF(0, 22), + min_t(u8, dev->cal.rx.freq_offset, 0xbf)); + val = mt76x0_phy_rf_rr(dev, MT_RF(0, 22)); /* Reset the DAC (Set B0.R73<7>=1, then set B0.R73<7>=0, and then set B0.R73<7>) during power up. */ - val = rf_rr(dev, MT_RF(0, 73)); + val = mt76x0_phy_rf_rr(dev, MT_RF(0, 73)); val |= 0x80; - rf_wr(dev, MT_RF(0, 73), val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 73), val); val &= ~0x80; - rf_wr(dev, MT_RF(0, 73), val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 73), val); val |= 0x80; - rf_wr(dev, MT_RF(0, 73), val); + mt76x0_phy_rf_wr(dev, MT_RF(0, 73), val); /* vcocal_en (initiate VCO calibration (reset after completion)) - It should be at the end of RF configuration. */ - rf_set(dev, MT_RF(0, 4), 0x80); + mt76x0_phy_rf_set(dev, MT_RF(0, 4), 0x80); } void mt76x0_phy_init(struct mt76x02_dev *dev) { INIT_DELAYED_WORK(&dev->cal_work, mt76x0_phy_calibration_work); - mt76x0_rf_init(dev); + mt76x0_phy_rf_init(dev); mt76x02_phy_set_rxpath(dev); mt76x02_phy_set_txdac(dev); }