From patchwork Wed Oct 10 09:14: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: 10634253 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 C6FE369B5 for ; Wed, 10 Oct 2018 09:14:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 967942921E for ; Wed, 10 Oct 2018 09:14:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A8412925D; Wed, 10 Oct 2018 09:14:40 +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 E6BB92921E for ; Wed, 10 Oct 2018 09:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727489AbeJJQfv (ORCPT ); Wed, 10 Oct 2018 12:35:51 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38290 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726932AbeJJQfv (ORCPT ); Wed, 10 Oct 2018 12:35:51 -0400 Received: by mail-wm1-f66.google.com with SMTP id 193-v6so4860760wme.3 for ; Wed, 10 Oct 2018 02:14:35 -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=+OaZkezujtUt6QSGIjpxuG3yTFJuwrWrH7aCZkmWk1Q=; b=O6kqDJKTnNIKS16jIj3JzXQuce99HhFcUwkqxk7HOIbSXuZOUXdDGQBdp8o7M9mh6N KUTxwW2Cr3MRajxbvlqFphcTfCRxB9SO3V9OIU/KL6gsW8lpOkaoH274PqrejmIhX7UW 9FQw6gjGNikX9GjdXLPE0MJKi7JIDxY3JXyW8ysUEhdIfqO6Vaoc36q2LSiYDsj+nst1 RIIM3YhCpscyh0dDlB+aCNiBytM8tDfLJoqHgONd0RAUcXtnyZqA3DH2gUu5tk77Wt9J JwiziZB28DsqRbjuGpJFSE9fQ+LpEZSW6ZjodW7F3sVsDmenA2A0OoMbtclw+L3FM9t/ DkEQ== X-Gm-Message-State: ABuFfog5ZKAMTSwD1Hsh5eGnNHmlvCPaxZDmvpu09GVAv0MssUldHxLz CJheqUurJ1xMV09F19nytCTh8xcvjZ0= X-Google-Smtp-Source: ACcGV62GKd6cqMfihu9xa5rnN6UPjlr9C887UTanwzRIbjxZlukdhwDPEtKgNZ96EFZTRlRItKENRg== X-Received: by 2002:a1c:845:: with SMTP id 66-v6mr139748wmi.61.1539162874505; Wed, 10 Oct 2018 02:14:34 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id 65-v6sm17715106wmm.36.2018.10.10.02.14.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Oct 2018 02:14:33 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 1/2] mt76x0: eeprom: introduce mt76x0_tssi_enabled routine Date: Wed, 10 Oct 2018 11:14:21 +0200 Message-Id: <89e1055c58beb475300558a6337a67a4b2678681.1539162246.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.1 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 dbb63d4c3bad..bc8c7273ee84 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 422114de695a..54156e860781 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 Wed Oct 10 09:14: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: 10634249 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 AD8E93CF1 for ; Wed, 10 Oct 2018 09:14:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FAAF28D2E for ; Wed, 10 Oct 2018 09:14:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 816BD29242; Wed, 10 Oct 2018 09:14:39 +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 6756128D2E for ; Wed, 10 Oct 2018 09:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727517AbeJJQfw (ORCPT ); Wed, 10 Oct 2018 12:35:52 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:50818 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbeJJQfw (ORCPT ); Wed, 10 Oct 2018 12:35:52 -0400 Received: by mail-wm1-f65.google.com with SMTP id i8-v6so4596479wmg.0 for ; Wed, 10 Oct 2018 02:14:36 -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=mT8eGMTQ/bXUU9CWYZxJdIn/xV9DdZwqe1PloPWP0/s=; b=czpGoXlp66/izNV7QLXibjGDvjrV80vbRH2E6Fz4xO8YL5ebNK1JvNYZqRADquc6q0 8pgCFwa6CYsgbJOGxvmPpxV0c8qVT1bGsn990PqldvS7vKKxpUlT2OtDUO79OdXYNWz2 f7d+T1jxH1gLnxDDB6b1L3cJXYursQOwrAY7Lq0h1cVECSWoXR0HyZ74zkGvBi1YJyNw 7TuhB3tnKHm3qpOY0/0AH6TNaCbD06aTNevjiAeWPPF9BBOMg216eKKKo+8lVD5hXStL 43yXmwd8IslBvQSgbPFx6xPbet4fjm4ramUbJTb6Ode0V0kIBOR1gd/bA8Ou3WmLSqNQ oBvw== X-Gm-Message-State: ABuFfojkP+OtAuwC7e7AiTd5+kQDoWmCQbccnGLSCwKpH9Gh4F3SeoAN cdAcWdBuZIU1wPR8PBmDt8CORw== X-Google-Smtp-Source: ACcGV60pCBSuYdqdvcNyM2w2N0vCY/20ag2ZB+0W4cmphKMIwyScL1UqRkhrleuSkWEEE+Qpf6JkoA== X-Received: by 2002:a1c:d9cc:: with SMTP id q195-v6mr130537wmg.23.1539162875619; Wed, 10 Oct 2018 02:14:35 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id 65-v6sm17715106wmm.36.2018.10.10.02.14.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Oct 2018 02:14:34 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH 2/2] mt76x0: phy: fix mt76x0_temp_sensor routine Date: Wed, 10 Oct 2018 11:14:22 +0200 Message-Id: <81232baeddb434362a3474842890ee9f316bfd67.1539162246.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.1 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 Fix configuration of register 67 on bank0 during temperature reading and use mt76_poll utility routine to poll core34 register. Moreover temperature compensation need 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 | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 29bc4e4623cd..e9254452c7f5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -763,48 +763,41 @@ 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) +static int mt76x0_temp_sensor(struct mt76x02_dev *dev, int *temp) { u8 rf_b7_73, rf_b0_66, rf_b0_67; - int cycle, temp; - u32 val; - s32 sval; + int val, err = 0; 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)); + err = -ETIMEDOUT; goto done; } - sval = mt76_rr(dev, MT_BBP(CORE, 35)) & 0xff; - if (!(sval & 0x80)) - sval &= 0x7f; /* Positive */ + val = mt76_rr(dev, MT_BBP(CORE, 35)) & 0xff; + if (!(val & BIT(7))) + val &= 0x7f; /* Positive */ else - sval |= 0xffffff00; /* Negative */ + val |= 0xffffff00; /* Negative */ - temp = (35 * (sval - dev->cal.rx.temp_offset)) / 10 + 25; + *temp = (35 * (val - dev->cal.rx.temp_offset)) / 10 + 25; 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); + + return err; } static void mt76x0_dynamic_vga_tuning(struct mt76x02_dev *dev) @@ -832,7 +825,11 @@ static void mt76x0_phy_calibrate(struct work_struct *work) cal_work.work); mt76x0_dynamic_vga_tuning(dev); - mt76x0_temp_sensor(dev); + if (!mt76x0_tssi_enabled(dev)) { + int temp; + + mt76x0_temp_sensor(dev, &temp); + } ieee80211_queue_delayed_work(dev->mt76.hw, &dev->cal_work, MT_CALIBRATE_INTERVAL);