From patchwork Sat Sep 22 11:45: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: 10611385 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 E0DBE161F for ; Sat, 22 Sep 2018 11:49:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1A642BF83 for ; Sat, 22 Sep 2018 11:49:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C63DB2BFE9; Sat, 22 Sep 2018 11:49:00 +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 0DEDB2BF83 for ; Sat, 22 Sep 2018 11:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728324AbeIVRjH (ORCPT ); Sat, 22 Sep 2018 13:39:07 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52454 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbeIVRjH (ORCPT ); Sat, 22 Sep 2018 13:39:07 -0400 Received: by mail-wm1-f66.google.com with SMTP id l7-v6so628130wme.2 for ; Sat, 22 Sep 2018 04:45: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; bh=8HgWpqArpJeS7NY1o5claOJdvi80nsyp2xx7v/U7/RY=; b=DINko0fdT4C4kmeZJUPhFrmfTEZkHRz7+44qDKlI+JQMGbL/uc7OF5hMdMPZ1Z4Paa TONk/XvkiQ3bVrYYEOTeJTysR2lcENnVw/JECJSgY+TpUCbv5AvZhRlYMjkmoJWYPH/p JLcZ+JQJXVkzHQOzlPcYsoFLuv9DbitxJWk23TWgrMy++WyHuN1ri1n0kv+e1iIQwb60 6lkvy2PRAgWrrtk6SsuCPs5vUS5jb1G2r89TGGcZ+heW3iSTKEda0zbi0BFHpWZepuDV esGc7c+HiqhPrdlv4uwob1RBGKOT5YcPvcPk2oY43I3H191msnkevUg6julDjdWFIjZ5 lUMw== X-Gm-Message-State: ABuFfogjlZSqt0IjZmi/4TmLvaTgRtoXaNAo/ZQvF3FKmNIS4CqO8krJ pvLub6KI3j28NpszzFYfoSE9/rRyzOI= X-Google-Smtp-Source: ANB0Vda08aYlK575+UM9kenWbV/n9G+l7Rq4h+VG3nxpQQHP9Jj7OGPm9CgSa8NGBBK3UxTMs/8qVQ== X-Received: by 2002:a1c:780c:: with SMTP id t12-v6mr1301653wmc.133.1537616747909; Sat, 22 Sep 2018 04:45:47 -0700 (PDT) Received: from localhost.localdomain ([151.66.72.6]) by smtp.gmail.com with ESMTPSA id u4-v6sm19600748wro.47.2018.09.22.04.45.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Sep 2018 04:45:47 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH 1/9] mt76: move mt76_rate_power in mt76_dev Date: Sat, 22 Sep 2018 13:45:29 +0200 Message-Id: <20180922114537.24004-2-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 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 mt76_rate_power data structure from mt76x2_dev to mt76_dev in order to share it with mt76x0 driver. Moreover move txpower_conf and txpower_cur in mt76_dev Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76.h | 30 +++++++++++-------- drivers/net/wireless/mediatek/mt76/mt76x2.h | 3 -- .../wireless/mediatek/mt76/mt76x2_debugfs.c | 20 ++++++------- .../mediatek/mt76/mt76x2_mac_common.c | 2 +- .../net/wireless/mediatek/mt76/mt76x2_main.c | 8 ++--- .../mediatek/mt76/mt76x2_phy_common.c | 6 ++-- .../wireless/mediatek/mt76/mt76x2_tx_common.c | 14 ++++----- .../net/wireless/mediatek/mt76/mt76x2u_main.c | 4 +-- 8 files changed, 44 insertions(+), 43 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index dc6a5f075f3d..15a5b0c89d86 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -275,6 +275,19 @@ struct mt76_sband { struct mt76_channel_state *chan; }; +struct mt76_rate_power { + union { + struct { + s8 cck[4]; + s8 ofdm[8]; + s8 stbc[10]; + s8 ht[16]; + s8 vht[10]; + }; + s8 all[48]; + }; +}; + /* addr req mask */ #define MT_VEND_TYPE_EEPROM BIT(31) #define MT_VEND_TYPE_CFG BIT(30) @@ -395,6 +408,10 @@ struct mt76_dev { struct debugfs_blob_wrapper otp; struct mt76_hw_cap cap; + struct mt76_rate_power rate_power; + int txpower_conf; + int txpower_cur; + u32 debugfs_reg; struct led_classdev led_cdev; @@ -418,19 +435,6 @@ enum mt76_phy_type { MT_PHY_TYPE_VHT, }; -struct mt76_rate_power { - union { - struct { - s8 cck[4]; - s8 ofdm[8]; - s8 stbc[10]; - s8 ht[16]; - s8 vht[10]; - }; - s8 all[48]; - }; -}; - struct mt76_rx_status { struct mt76_wcid *wcid; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2.h b/drivers/net/wireless/mediatek/mt76/mt76x2.h index 784962913d9a..a6dd35d00968 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2.h @@ -82,8 +82,6 @@ struct mt76x2_dev { struct mutex mutex; const u16 *beacon_offsets; - int txpower_conf; - int txpower_cur; u8 txdone_seq; DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x02_tx_status); @@ -113,7 +111,6 @@ struct mt76x2_dev { s8 target_power; s8 target_power_delta[2]; - struct mt76_rate_power rate_power; bool enable_tpc; u8 coverage_class; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c index 45f3439a6563..527c94d07d67 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c @@ -55,16 +55,16 @@ static int read_txpower(struct seq_file *file, void *data) mt76_seq_puts_array(file, "Delta", dev->target_power_delta, ARRAY_SIZE(dev->target_power_delta)); - mt76_seq_puts_array(file, "CCK", dev->rate_power.cck, - ARRAY_SIZE(dev->rate_power.cck)); - mt76_seq_puts_array(file, "OFDM", dev->rate_power.ofdm, - ARRAY_SIZE(dev->rate_power.ofdm)); - mt76_seq_puts_array(file, "STBC", dev->rate_power.stbc, - ARRAY_SIZE(dev->rate_power.stbc)); - mt76_seq_puts_array(file, "HT", dev->rate_power.ht, - ARRAY_SIZE(dev->rate_power.ht)); - mt76_seq_puts_array(file, "VHT", dev->rate_power.vht, - ARRAY_SIZE(dev->rate_power.vht)); + mt76_seq_puts_array(file, "CCK", dev->mt76.rate_power.cck, + ARRAY_SIZE(dev->mt76.rate_power.cck)); + mt76_seq_puts_array(file, "OFDM", dev->mt76.rate_power.ofdm, + ARRAY_SIZE(dev->mt76.rate_power.ofdm)); + mt76_seq_puts_array(file, "STBC", dev->mt76.rate_power.stbc, + ARRAY_SIZE(dev->mt76.rate_power.stbc)); + mt76_seq_puts_array(file, "HT", dev->mt76.rate_power.ht, + ARRAY_SIZE(dev->mt76.rate_power.ht)); + mt76_seq_puts_array(file, "VHT", dev->mt76.rate_power.vht, + ARRAY_SIZE(dev->mt76.rate_power.vht)); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_mac_common.c b/drivers/net/wireless/mediatek/mt76/mt76x2_mac_common.c index 126650742ba4..ed4f56a3aae9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_mac_common.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_mac_common.c @@ -100,7 +100,7 @@ void mt76x2_mac_write_txwi(struct mt76x2_dev *dev, struct mt76x02_txwi *txwi, } spin_unlock_bh(&dev->mt76.lock); - txpwr_adj = mt76x2_tx_get_txpwr_adj(dev, dev->txpower_conf, + txpwr_adj = mt76x2_tx_get_txpwr_adj(dev, dev->mt76.txpower_conf, max_txpwr_adj); txwi->ctl2 = FIELD_PREP(MT_TX_PWR_ADJ, txpwr_adj); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_main.c b/drivers/net/wireless/mediatek/mt76/mt76x2_main.c index 7f0a89be154c..24b13eeba8af 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_main.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_main.c @@ -106,14 +106,14 @@ mt76x2_config(struct ieee80211_hw *hw, u32 changed) } if (changed & IEEE80211_CONF_CHANGE_POWER) { - dev->txpower_conf = hw->conf.power_level * 2; + dev->mt76.txpower_conf = hw->conf.power_level * 2; /* convert to per-chain power for 2x2 devices */ - dev->txpower_conf -= 6; + dev->mt76.txpower_conf -= 6; if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state)) { mt76x2_phy_set_txpower(dev); - mt76x2_tx_set_txpwr_auto(dev, dev->txpower_conf); + mt76x2_tx_set_txpwr_auto(dev, dev->mt76.txpower_conf); } } @@ -206,7 +206,7 @@ mt76x2_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif, int *dbm) { struct mt76x2_dev *dev = hw->priv; - *dbm = dev->txpower_cur / 2; + *dbm = dev->mt76.txpower_cur / 2; /* convert from per-chain power to combined output on 2x2 devices */ *dbm += 3; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c b/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c index fba01e179f56..e6baad9f4316 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c @@ -192,8 +192,8 @@ void mt76x2_phy_set_txpower(struct mt76x2_dev *dev) mt76x2_get_rate_power(dev, &t, chan); mt76x2_add_rate_power_offset(&t, txp.chain[0].target_power); - mt76x2_limit_rate_power(&t, dev->txpower_conf); - dev->txpower_cur = mt76x2_get_max_rate_power(&t); + mt76x2_limit_rate_power(&t, dev->mt76.txpower_conf); + dev->mt76.txpower_cur = mt76x2_get_max_rate_power(&t); base_power = mt76x2_get_min_rate_power(&t); delta += base_power - txp.chain[0].target_power; @@ -215,7 +215,7 @@ void mt76x2_phy_set_txpower(struct mt76x2_dev *dev) dev->target_power = txp.chain[0].target_power; dev->target_power_delta[0] = txp_0 - txp.chain[0].target_power; dev->target_power_delta[1] = txp_1 - txp.chain[0].target_power; - dev->rate_power = t; + dev->mt76.rate_power = t; mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_0, txp_0); mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_1, txp_1); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_tx_common.c b/drivers/net/wireless/mediatek/mt76/mt76x2_tx_common.c index dbb3071bed1b..1ec3c293e2c4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_tx_common.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_tx_common.c @@ -57,23 +57,23 @@ s8 mt76x2_tx_get_max_txpwr_adj(struct mt76_dev *mdev, u8 mcs = ieee80211_rate_get_vht_mcs(rate); if (mcs == 8 || mcs == 9) { - max_txpwr = dev->rate_power.vht[8]; + max_txpwr = mdev->rate_power.vht[8]; } else { u8 nss, idx; nss = ieee80211_rate_get_vht_nss(rate); idx = ((nss - 1) << 3) + mcs; - max_txpwr = dev->rate_power.ht[idx & 0xf]; + max_txpwr = mdev->rate_power.ht[idx & 0xf]; } } else if (rate->flags & IEEE80211_TX_RC_MCS) { - max_txpwr = dev->rate_power.ht[rate->idx & 0xf]; + max_txpwr = mdev->rate_power.ht[rate->idx & 0xf]; } else { enum nl80211_band band = dev->mt76.chandef.chan->band; if (band == NL80211_BAND_2GHZ) { const struct ieee80211_rate *r; struct wiphy *wiphy = mt76_hw(dev)->wiphy; - struct mt76_rate_power *rp = &dev->rate_power; + struct mt76_rate_power *rp = &mdev->rate_power; r = &wiphy->bands[band]->bitrates[rate->idx]; if (r->flags & IEEE80211_RATE_SHORT_PREAMBLE) @@ -81,7 +81,7 @@ s8 mt76x2_tx_get_max_txpwr_adj(struct mt76_dev *mdev, else max_txpwr = rp->ofdm[r->hw_value & 0x7]; } else { - max_txpwr = dev->rate_power.ofdm[rate->idx & 0x7]; + max_txpwr = mdev->rate_power.ofdm[rate->idx & 0x7]; } } @@ -91,7 +91,7 @@ EXPORT_SYMBOL_GPL(mt76x2_tx_get_max_txpwr_adj); s8 mt76x2_tx_get_txpwr_adj(struct mt76x2_dev *dev, s8 txpwr, s8 max_txpwr_adj) { - txpwr = min_t(s8, txpwr, dev->txpower_conf); + txpwr = min_t(s8, txpwr, dev->mt76.txpower_conf); txpwr -= (dev->target_power + dev->target_power_delta[0]); txpwr = min_t(s8, txpwr, max_txpwr_adj); @@ -109,7 +109,7 @@ void mt76x2_tx_set_txpwr_auto(struct mt76x2_dev *dev, s8 txpwr) s8 txpwr_adj; txpwr_adj = mt76x2_tx_get_txpwr_adj(dev, txpwr, - dev->rate_power.ofdm[4]); + dev->mt76.rate_power.ofdm[4]); mt76_rmw_field(dev, MT_PROT_AUTO_TX_CFG, MT_PROT_AUTO_TX_CFG_PROT_PADJ, txpwr_adj); mt76_rmw_field(dev, MT_PROT_AUTO_TX_CFG, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u_main.c b/drivers/net/wireless/mediatek/mt76/mt76x2u_main.c index 620aeb3eb79f..a80704568780 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u_main.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u_main.c @@ -128,10 +128,10 @@ mt76x2u_config(struct ieee80211_hw *hw, u32 changed) } if (changed & IEEE80211_CONF_CHANGE_POWER) { - dev->txpower_conf = hw->conf.power_level * 2; + dev->mt76.txpower_conf = hw->conf.power_level * 2; /* convert to per-chain power for 2x2 devices */ - dev->txpower_conf -= 6; + dev->mt76.txpower_conf -= 6; if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state)) mt76x2_phy_set_txpower(dev); From patchwork Sat Sep 22 11:45:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10611387 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 31BF4157B for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E6FF2BF92 for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 134842BFE9; Sat, 22 Sep 2018 11:49: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 38BAD2BF92 for ; Sat, 22 Sep 2018 11:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728421AbeIVRjJ (ORCPT ); Sat, 22 Sep 2018 13:39:09 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44059 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727474AbeIVRjI (ORCPT ); Sat, 22 Sep 2018 13:39:08 -0400 Received: by mail-wr1-f66.google.com with SMTP id v16-v6so15221480wro.11 for ; Sat, 22 Sep 2018 04:45: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; bh=4f/B/BA1d85Zds4r1N2tw/0oTAVSdgir1LZX8hpR1bU=; b=gj4ZJiL15YK3yFKCQqro0IRI2tFR3GadewxUjuA3qnc3Ofs59ZkRZXd7xO7v1y9v/K jMHZLR3qTAiJw6pAo5SyHAMeET1W2nYdypPQe4Jt+4Fm/K1z/V5/WxYI2XykfMd14le5 nV+RMGJ5Yc4iXx4rC5Rck/FOygqAvKsSEcY4jVjmIZPl/O/R3lh7qbZDOgaWOltYIMU/ Jn1z3crpYQ+uqk3pbu6NnDRweUvaYghkT2EswuqDCkUpRWu3YryBaD6GPr9tFkVi1BZL M5sGPBoaciobCxz8t4RaemwcMmn73ccFsrdN7mkACX1R3hygHZ4dYvek1Ep1iVanXGDn fidw== X-Gm-Message-State: ABuFfojP3oDDmaFAOlsVnHgsXlLgB+O7WmXw9qM/oP4067eoXna4mRNk +5uJdiiivmHDCg1UzkLIJFL7z/VWzzs= X-Google-Smtp-Source: ACcGV61PGnvVwuS9l/1LhrFjnzgVY1/BgDFUPEH/riEzH31RMso98s7Soyt5ehAOvkSQkfNogteafQ== X-Received: by 2002:adf:d20a:: with SMTP id g10-v6mr1802161wri.66.1537616749120; Sat, 22 Sep 2018 04:45:49 -0700 (PDT) Received: from localhost.localdomain ([151.66.72.6]) by smtp.gmail.com with ESMTPSA id u4-v6sm19600748wro.47.2018.09.22.04.45.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Sep 2018 04:45:48 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH 2/9] mt76: add mt76x02_phy_set_txpower utility routine Date: Sat, 22 Sep 2018 13:45:30 +0200 Message-Id: <20180922114537.24004-3-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 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_phy_set_txpower utility routine in mt76x02_phy.c in order to be reused in mt76x0 tx power management code. Moreover move following routines in mt76x02-lib module: - mt76x02_tx_power_mask - mt76x02_get_max_rate_power - mt76x02_limit_rate_power - mt76x02_add_rate_power_offset Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/Makefile | 2 +- .../net/wireless/mediatek/mt76/mt76x02_phy.c | 97 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt76x02_phy.h | 27 ++++++ .../wireless/mediatek/mt76/mt76x2_eeprom.c | 12 --- .../wireless/mediatek/mt76/mt76x2_eeprom.h | 1 - .../mediatek/mt76/mt76x2_init_common.c | 3 +- .../mediatek/mt76/mt76x2_phy_common.c | 60 ++---------- 7 files changed, 133 insertions(+), 69 deletions(-) create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x02_phy.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x02_phy.h diff --git a/drivers/net/wireless/mediatek/mt76/Makefile b/drivers/net/wireless/mediatek/mt76/Makefile index dbe0ec020391..1fc7450650ee 100644 --- a/drivers/net/wireless/mediatek/mt76/Makefile +++ b/drivers/net/wireless/mediatek/mt76/Makefile @@ -16,7 +16,7 @@ CFLAGS_trace.o := -I$(src) CFLAGS_usb_trace.o := -I$(src) mt76x02-lib-y := mt76x02_util.o mt76x02_mac.o mt76x02_mcu.o \ - mt76x02_eeprom.o + mt76x02_eeprom.o mt76x02_phy.o mt76x02-usb-y := mt76x02_usb_mcu.o mt76x02_usb_core.o diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c new file mode 100644 index 000000000000..969854b69981 --- /dev/null +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.c @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2016 Felix Fietkau + * Copyright (C) 2018 Lorenzo Bianconi + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include "mt76.h" +#include "mt76x02_phy.h" + +static u32 +mt76x02_tx_power_mask(u8 v1, u8 v2, u8 v3, u8 v4) +{ + u32 val = 0; + + val |= (v1 & (BIT(6) - 1)) << 0; + val |= (v2 & (BIT(6) - 1)) << 8; + val |= (v3 & (BIT(6) - 1)) << 16; + val |= (v4 & (BIT(6) - 1)) << 24; + return val; +} + +int mt76x02_get_max_rate_power(struct mt76_rate_power *r) +{ + s8 ret = 0; + int i; + + for (i = 0; i < sizeof(r->all); i++) + ret = max(ret, r->all[i]); + + return ret; +} +EXPORT_SYMBOL_GPL(mt76x02_get_max_rate_power); + +void mt76x02_limit_rate_power(struct mt76_rate_power *r, int limit) +{ + int i; + + for (i = 0; i < sizeof(r->all); i++) + if (r->all[i] > limit) + r->all[i] = limit; +} +EXPORT_SYMBOL_GPL(mt76x02_limit_rate_power); + +void mt76x02_add_rate_power_offset(struct mt76_rate_power *r, int offset) +{ + int i; + + for (i = 0; i < sizeof(r->all); i++) + r->all[i] += offset; +} +EXPORT_SYMBOL_GPL(mt76x02_add_rate_power_offset); + +void mt76x02_phy_set_txpower(struct mt76_dev *dev, int txp_0, int txp_1) +{ + struct mt76_rate_power *t = &dev->rate_power; + + __mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_0, + txp_0); + __mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_1, + txp_1); + + __mt76_wr(dev, MT_TX_PWR_CFG_0, + mt76x02_tx_power_mask(t->cck[0], t->cck[2], t->ofdm[0], + t->ofdm[2])); + __mt76_wr(dev, MT_TX_PWR_CFG_1, + mt76x02_tx_power_mask(t->ofdm[4], t->ofdm[6], t->ht[0], + t->ht[2])); + __mt76_wr(dev, MT_TX_PWR_CFG_2, + mt76x02_tx_power_mask(t->ht[4], t->ht[6], t->ht[8], + t->ht[10])); + __mt76_wr(dev, MT_TX_PWR_CFG_3, + mt76x02_tx_power_mask(t->ht[12], t->ht[14], t->stbc[0], + t->stbc[2])); + __mt76_wr(dev, MT_TX_PWR_CFG_4, + mt76x02_tx_power_mask(t->stbc[4], t->stbc[6], 0, 0)); + __mt76_wr(dev, MT_TX_PWR_CFG_7, + mt76x02_tx_power_mask(t->ofdm[7], t->vht[8], t->ht[7], + t->vht[9])); + __mt76_wr(dev, MT_TX_PWR_CFG_8, + mt76x02_tx_power_mask(t->ht[14], 0, t->vht[8], t->vht[9])); + __mt76_wr(dev, MT_TX_PWR_CFG_9, + mt76x02_tx_power_mask(t->ht[7], 0, t->stbc[8], t->stbc[9])); +} +EXPORT_SYMBOL_GPL(mt76x02_phy_set_txpower); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h new file mode 100644 index 000000000000..25567f9f5070 --- /dev/null +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_phy.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2018 Lorenzo Bianconi + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __MT76x02_PHY_H +#define __MT76x02_PHY_H + +#include "mt76x02_regs.h" + +void mt76x02_add_rate_power_offset(struct mt76_rate_power *r, int offset); +void mt76x02_phy_set_txpower(struct mt76_dev *dev, int txp_0, int txp_2); +void mt76x02_limit_rate_power(struct mt76_rate_power *r, int limit); +int mt76x02_get_max_rate_power(struct mt76_rate_power *r); + +#endif /* __MT76x02_PHY_H */ diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c index bb31aecca77a..4e287d5e2137 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -381,18 +381,6 @@ void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76_rate_power *t, } EXPORT_SYMBOL_GPL(mt76x2_get_rate_power); -int mt76x2_get_max_rate_power(struct mt76_rate_power *r) -{ - int i; - s8 ret = 0; - - for (i = 0; i < sizeof(r->all); i++) - ret = max(ret, r->all[i]); - - return ret; -} -EXPORT_SYMBOL_GPL(mt76x2_get_max_rate_power); - static void mt76x2_get_power_info_2g(struct mt76x2_dev *dev, struct mt76x2_tx_power_info *t, struct ieee80211_channel *chan, int chain, int offset) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h index 650f9564f0f4..c2e99bbeac3b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h @@ -53,7 +53,6 @@ struct mt76x2_temp_comp { void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76_rate_power *t, struct ieee80211_channel *chan); -int mt76x2_get_max_rate_power(struct mt76_rate_power *r); void mt76x2_get_power_info(struct mt76x2_dev *dev, struct mt76x2_tx_power_info *t, struct ieee80211_channel *chan); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_init_common.c b/drivers/net/wireless/mediatek/mt76/mt76x2_init_common.c index 31de3365cdb8..d13da7ad86ee 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_init_common.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_init_common.c @@ -17,6 +17,7 @@ #include "mt76x2.h" #include "mt76x2_eeprom.h" +#include "mt76x02_phy.h" static void mt76x2_set_wlan_state(struct mt76x2_dev *dev, bool enable) @@ -214,7 +215,7 @@ void mt76x2_init_txpower(struct mt76x2_dev *dev, mt76x2_get_rate_power(dev, &t, chan); - chan->max_power = mt76x2_get_max_rate_power(&t) + + chan->max_power = mt76x02_get_max_rate_power(&t) + target_power; chan->max_power /= 2; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c b/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c index e6baad9f4316..dd32e756d8b7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c @@ -18,6 +18,7 @@ #include "mt76x2.h" #include "mt76x2_eeprom.h" #include "mt76x2_mcu.h" +#include "mt76x02_phy.h" static void mt76x2_adjust_high_lna_gain(struct mt76x2_dev *dev, int reg, s8 offset) @@ -124,37 +125,6 @@ void mt76x2_phy_set_txpower_regs(struct mt76x2_dev *dev, } EXPORT_SYMBOL_GPL(mt76x2_phy_set_txpower_regs); -static void -mt76x2_limit_rate_power(struct mt76_rate_power *r, int limit) -{ - int i; - - for (i = 0; i < sizeof(r->all); i++) - if (r->all[i] > limit) - r->all[i] = limit; -} - -static u32 -mt76x2_tx_power_mask(u8 v1, u8 v2, u8 v3, u8 v4) -{ - u32 val = 0; - - val |= (v1 & (BIT(6) - 1)) << 0; - val |= (v2 & (BIT(6) - 1)) << 8; - val |= (v3 & (BIT(6) - 1)) << 16; - val |= (v4 & (BIT(6) - 1)) << 24; - return val; -} - -static void -mt76x2_add_rate_power_offset(struct mt76_rate_power *r, int offset) -{ - int i; - - for (i = 0; i < sizeof(r->all); i++) - r->all[i] += offset; -} - static int mt76x2_get_min_rate_power(struct mt76_rate_power *r) { @@ -191,9 +161,9 @@ void mt76x2_phy_set_txpower(struct mt76x2_dev *dev) delta = txp.delta_bw80; mt76x2_get_rate_power(dev, &t, chan); - mt76x2_add_rate_power_offset(&t, txp.chain[0].target_power); - mt76x2_limit_rate_power(&t, dev->mt76.txpower_conf); - dev->mt76.txpower_cur = mt76x2_get_max_rate_power(&t); + mt76x02_add_rate_power_offset(&t, txp.chain[0].target_power); + mt76x02_limit_rate_power(&t, dev->mt76.txpower_conf); + dev->mt76.txpower_cur = mt76x02_get_max_rate_power(&t); base_power = mt76x2_get_min_rate_power(&t); delta += base_power - txp.chain[0].target_power; @@ -211,31 +181,13 @@ void mt76x2_phy_set_txpower(struct mt76x2_dev *dev) txp_1 = 0x2f; } - mt76x2_add_rate_power_offset(&t, -base_power); + mt76x02_add_rate_power_offset(&t, -base_power); dev->target_power = txp.chain[0].target_power; dev->target_power_delta[0] = txp_0 - txp.chain[0].target_power; dev->target_power_delta[1] = txp_1 - txp.chain[0].target_power; dev->mt76.rate_power = t; - mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_0, txp_0); - mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_1, txp_1); - - mt76_wr(dev, MT_TX_PWR_CFG_0, - mt76x2_tx_power_mask(t.cck[0], t.cck[2], t.ofdm[0], t.ofdm[2])); - mt76_wr(dev, MT_TX_PWR_CFG_1, - mt76x2_tx_power_mask(t.ofdm[4], t.ofdm[6], t.ht[0], t.ht[2])); - mt76_wr(dev, MT_TX_PWR_CFG_2, - mt76x2_tx_power_mask(t.ht[4], t.ht[6], t.ht[8], t.ht[10])); - mt76_wr(dev, MT_TX_PWR_CFG_3, - mt76x2_tx_power_mask(t.ht[12], t.ht[14], t.stbc[0], t.stbc[2])); - mt76_wr(dev, MT_TX_PWR_CFG_4, - mt76x2_tx_power_mask(t.stbc[4], t.stbc[6], 0, 0)); - mt76_wr(dev, MT_TX_PWR_CFG_7, - mt76x2_tx_power_mask(t.ofdm[7], t.vht[8], t.ht[7], t.vht[9])); - mt76_wr(dev, MT_TX_PWR_CFG_8, - mt76x2_tx_power_mask(t.ht[14], 0, t.vht[8], t.vht[9])); - mt76_wr(dev, MT_TX_PWR_CFG_9, - mt76x2_tx_power_mask(t.ht[7], 0, t.stbc[8], t.stbc[9])); + mt76x02_phy_set_txpower(&dev->mt76, txp_0, txp_1); } EXPORT_SYMBOL_GPL(mt76x2_phy_set_txpower); From patchwork Sat Sep 22 11:45:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10611397 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 6CB69157B for ; Sat, 22 Sep 2018 11:49:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D7082BF7F for ; Sat, 22 Sep 2018 11:49:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 525852BF9B; Sat, 22 Sep 2018 11:49:02 +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 59EAD2BF7F for ; Sat, 22 Sep 2018 11:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728618AbeIVRjJ (ORCPT ); Sat, 22 Sep 2018 13:39:09 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36340 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbeIVRjJ (ORCPT ); Sat, 22 Sep 2018 13:39:09 -0400 Received: by mail-wm1-f65.google.com with SMTP id y13-v6so987470wmi.1 for ; Sat, 22 Sep 2018 04:45: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; bh=Bn9IWtird3q6jCPLfxMn7Oe06u3EHQYqnT1tjxvp2yM=; b=g/E4//ZOOiNwt2Tbj24nenW+kn4ME1NXh7K4EeUJOwFzi61dKcGUk3dBxFpNQA1fyl EE3hHVgrfK00m77TNeJXYg0glEl3NE1btiwD0Yn3VNvDRDYuFVyEoeJ16PCI8wDCylWh w0vZzDjeOLPyxXOmJaAMLcxjfpcb6MoBI3AIkLStPLq4E0q1/xVW2p18twoeTsUtpV3h eI6tCUTliZV04aU7YpGCuWJ8LT3F6lttAnwN+hR2r53IdZIbMICwU2pE/bq27+0Lw2no O2pWxOOzEw0aE6R/r+tGGjFgISy9nzsHZY+MIR86eP1Ph6bDcEZMPHe5mRZpJUSDUy2R F5UA== X-Gm-Message-State: APzg51DGESxhqqC4LUqoZHFE/BmPfbGEI7Is705HIFRhzUnUzpGVQ5ZT z/KzhIaOPhsChKNl3Yd8D7ZMlg== X-Google-Smtp-Source: ACcGV63JBeocpFoHP2qxZr9PXyU2XOWW6uGI9CgCokfFI+QbkeTx6FxtbWPZiPWi4RvaGt3J4IRlTw== X-Received: by 2002:a1c:d98a:: with SMTP id q132-v6mr1311254wmg.78.1537616750313; Sat, 22 Sep 2018 04:45:50 -0700 (PDT) Received: from localhost.localdomain ([151.66.72.6]) by smtp.gmail.com with ESMTPSA id u4-v6sm19600748wro.47.2018.09.22.04.45.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Sep 2018 04:45:49 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH 3/9] mt76: move rate_txpower handler in mt76 debugfs Date: Sat, 22 Sep 2018 13:45:31 +0200 Message-Id: <20180922114537.24004-4-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 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 rate_txpower handler in mt76 debugfs in order to be reused in mt76x0 driver and remove duplicated code Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/debugfs.c | 19 +++++++++++++++++++ .../wireless/mediatek/mt76/mt76x2_debugfs.c | 10 ---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/debugfs.c b/drivers/net/wireless/mediatek/mt76/debugfs.c index 03ce635334fa..a5adf22c3ffa 100644 --- a/drivers/net/wireless/mediatek/mt76/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/debugfs.c @@ -68,6 +68,23 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, } EXPORT_SYMBOL_GPL(mt76_seq_puts_array); +static int mt76_read_rate_txpower(struct seq_file *s, void *data) +{ + struct mt76_dev *dev = dev_get_drvdata(s->private); + + mt76_seq_puts_array(s, "CCK", dev->rate_power.cck, + ARRAY_SIZE(dev->rate_power.cck)); + mt76_seq_puts_array(s, "OFDM", dev->rate_power.ofdm, + ARRAY_SIZE(dev->rate_power.ofdm)); + mt76_seq_puts_array(s, "STBC", dev->rate_power.stbc, + ARRAY_SIZE(dev->rate_power.stbc)); + mt76_seq_puts_array(s, "HT", dev->rate_power.ht, + ARRAY_SIZE(dev->rate_power.ht)); + mt76_seq_puts_array(s, "VHT", dev->rate_power.vht, + ARRAY_SIZE(dev->rate_power.vht)); + return 0; +} + struct dentry *mt76_register_debugfs(struct mt76_dev *dev) { struct dentry *dir; @@ -84,6 +101,8 @@ struct dentry *mt76_register_debugfs(struct mt76_dev *dev) if (dev->otp.data) debugfs_create_blob("otp", 0400, dir, &dev->otp); debugfs_create_devm_seqfile(dev->dev, "queues", dir, mt76_queues_read); + debugfs_create_devm_seqfile(dev->dev, "rate_txpower", dir, + mt76_read_rate_txpower); return dir; } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c index 527c94d07d67..ea373bae1522 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c @@ -55,16 +55,6 @@ static int read_txpower(struct seq_file *file, void *data) mt76_seq_puts_array(file, "Delta", dev->target_power_delta, ARRAY_SIZE(dev->target_power_delta)); - mt76_seq_puts_array(file, "CCK", dev->mt76.rate_power.cck, - ARRAY_SIZE(dev->mt76.rate_power.cck)); - mt76_seq_puts_array(file, "OFDM", dev->mt76.rate_power.ofdm, - ARRAY_SIZE(dev->mt76.rate_power.ofdm)); - mt76_seq_puts_array(file, "STBC", dev->mt76.rate_power.stbc, - ARRAY_SIZE(dev->mt76.rate_power.stbc)); - mt76_seq_puts_array(file, "HT", dev->mt76.rate_power.ht, - ARRAY_SIZE(dev->mt76.rate_power.ht)); - mt76_seq_puts_array(file, "VHT", dev->mt76.rate_power.vht, - ARRAY_SIZE(dev->mt76.rate_power.vht)); return 0; } From patchwork Sat Sep 22 11:45:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10611393 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 E6CF3161F for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D63E42BF83 for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C356E2C0D3; Sat, 22 Sep 2018 11:49: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 9A8A62BF9B for ; Sat, 22 Sep 2018 11:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728703AbeIVRjL (ORCPT ); Sat, 22 Sep 2018 13:39:11 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35096 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727474AbeIVRjL (ORCPT ); Sat, 22 Sep 2018 13:39:11 -0400 Received: by mail-wm1-f67.google.com with SMTP id o18-v6so5766941wmc.0 for ; Sat, 22 Sep 2018 04:45: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; bh=pJgTiy4AcqP5y9N7jFckxjaw5nJpFV9uWn6K7n4ueHc=; b=f1zMp3XJuUHXt3SYnArnwN1HiB66nA0ONcytpQfPChkChhA9o425mWw/mspvI3jrqo b2Xasjy7AaIeRwoyglVPznnGVWVEXGXsS8IK7GEfgIMciurYziTVlpAW79hvJueWTIfb RKbL3WmwTqPLb785O+yeWsXGtPdoCDrYX2I3ZzqEyasqVlTmzxCu4M9hgu9uIxHebsxk MqpypwM60b5bGVbxEifzCn/48rJbpFAzhThLIeXtybNjnQS9Hl7ttatkduOvlz4gl3SA cYCZRVwrtslo/yHWtkDLQR2nMek4UrBYG4DfJShL4Na630eVHHQL7VdmETaFep00bfA3 bnfg== X-Gm-Message-State: APzg51BGUd2VKVsD988MnmTmOtbCzezCga+yaXA2s+oEbsXnczMXYxNT EWvs5Twd1IwH9groBVeDnjQ/VVZfxS0= X-Google-Smtp-Source: ANB0VdZ1ZlRoW5Dw6QIRIRKCAbfcJ6Ir1UF0mviaPGdm2a5VXWY+nWBZqkdfyOSJk0nE3ZJm5+tgww== X-Received: by 2002:a1c:a614:: with SMTP id p20-v6mr1422287wme.68.1537616751310; Sat, 22 Sep 2018 04:45:51 -0700 (PDT) Received: from localhost.localdomain ([151.66.72.6]) by smtp.gmail.com with ESMTPSA id u4-v6sm19600748wro.47.2018.09.22.04.45.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Sep 2018 04:45:50 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH 4/9] mt76: move mt76x02_rate_power_val in mt76x02-lib module Date: Sat, 22 Sep 2018 13:45:32 +0200 Message-Id: <20180922114537.24004-5-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 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_rate_power_val and mt76x2_sign_extend_optional utility routines in mt76x02_eeprom.h in order to reuse them in mt76x0 eeprom parsing Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x02_eeprom.h | 16 +++++ .../wireless/mediatek/mt76/mt76x2_eeprom.c | 65 +++++++------------ 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 9339514fb073..c3d8920a8127 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -152,6 +152,22 @@ mt76x02_sign_extend(u32 val, unsigned int size) return sign ? val : -val; } +static inline int +mt76x02_sign_extend_optional(u32 val, unsigned int size) +{ + bool enable = val & BIT(size); + + return enable ? mt76x02_sign_extend(val, size) : 0; +} + +static inline s8 mt76x02_rate_power_val(u8 val) +{ + if (!mt76x02_field_valid(val)) + return 0; + + return mt76x02_sign_extend_optional(val, 7); +} + static inline int mt76x02_eeprom_get(struct mt76_dev *dev, enum mt76x02_eeprom_field field) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c index 4e287d5e2137..8c8ba3ee6da5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -195,14 +195,6 @@ mt76x2_eeprom_load(struct mt76x2_dev *dev) return 0; } -static inline int -mt76x2_sign_extend_optional(u32 val, unsigned int size) -{ - bool enable = val & BIT(size); - - return enable ? mt76x02_sign_extend(val, size) : 0; -} - static void mt76x2_set_rx_gain_group(struct mt76x2_dev *dev, u8 val) { @@ -228,7 +220,7 @@ mt76x2_set_rssi_offset(struct mt76x2_dev *dev, int chain, u8 val) return; } - dest[chain] = mt76x2_sign_extend_optional(val, 7); + dest[chain] = mt76x02_sign_extend_optional(val, 7); } static enum mt76x2_cal_channel_group @@ -305,15 +297,6 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev) } EXPORT_SYMBOL_GPL(mt76x2_read_rx_gain); -static s8 -mt76x2_rate_power_val(u8 val) -{ - if (!mt76x02_field_valid(val)) - return 0; - - return mt76x2_sign_extend_optional(val, 7); -} - void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76_rate_power *t, struct ieee80211_channel *chan) { @@ -325,8 +308,8 @@ void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76_rate_power *t, memset(t, 0, sizeof(*t)); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_CCK); - t->cck[0] = t->cck[1] = mt76x2_rate_power_val(val); - t->cck[2] = t->cck[3] = mt76x2_rate_power_val(val >> 8); + t->cck[0] = t->cck[1] = mt76x02_rate_power_val(val); + t->cck[2] = t->cck[3] = mt76x02_rate_power_val(val >> 8); if (is_5ghz) val = mt76x02_eeprom_get(&dev->mt76, @@ -334,8 +317,8 @@ void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76_rate_power *t, else val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_OFDM_2G_6M); - t->ofdm[0] = t->ofdm[1] = mt76x2_rate_power_val(val); - t->ofdm[2] = t->ofdm[3] = mt76x2_rate_power_val(val >> 8); + t->ofdm[0] = t->ofdm[1] = mt76x02_rate_power_val(val); + t->ofdm[2] = t->ofdm[3] = mt76x02_rate_power_val(val >> 8); if (is_5ghz) val = mt76x02_eeprom_get(&dev->mt76, @@ -343,37 +326,37 @@ void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76_rate_power *t, else val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_OFDM_2G_24M); - t->ofdm[4] = t->ofdm[5] = mt76x2_rate_power_val(val); - t->ofdm[6] = t->ofdm[7] = mt76x2_rate_power_val(val >> 8); + t->ofdm[4] = t->ofdm[5] = mt76x02_rate_power_val(val); + t->ofdm[6] = t->ofdm[7] = mt76x02_rate_power_val(val >> 8); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_HT_MCS0); - t->ht[0] = t->ht[1] = mt76x2_rate_power_val(val); - t->ht[2] = t->ht[3] = mt76x2_rate_power_val(val >> 8); + t->ht[0] = t->ht[1] = mt76x02_rate_power_val(val); + t->ht[2] = t->ht[3] = mt76x02_rate_power_val(val >> 8); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_HT_MCS4); - t->ht[4] = t->ht[5] = mt76x2_rate_power_val(val); - t->ht[6] = t->ht[7] = mt76x2_rate_power_val(val >> 8); + t->ht[4] = t->ht[5] = mt76x02_rate_power_val(val); + t->ht[6] = t->ht[7] = mt76x02_rate_power_val(val >> 8); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_HT_MCS8); - t->ht[8] = t->ht[9] = mt76x2_rate_power_val(val); - t->ht[10] = t->ht[11] = mt76x2_rate_power_val(val >> 8); + t->ht[8] = t->ht[9] = mt76x02_rate_power_val(val); + t->ht[10] = t->ht[11] = mt76x02_rate_power_val(val >> 8); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_HT_MCS12); - t->ht[12] = t->ht[13] = mt76x2_rate_power_val(val); - t->ht[14] = t->ht[15] = mt76x2_rate_power_val(val >> 8); + t->ht[12] = t->ht[13] = mt76x02_rate_power_val(val); + t->ht[14] = t->ht[15] = mt76x02_rate_power_val(val >> 8); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_VHT_MCS0); - t->vht[0] = t->vht[1] = mt76x2_rate_power_val(val); - t->vht[2] = t->vht[3] = mt76x2_rate_power_val(val >> 8); + t->vht[0] = t->vht[1] = mt76x02_rate_power_val(val); + t->vht[2] = t->vht[3] = mt76x02_rate_power_val(val >> 8); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_VHT_MCS4); - t->vht[4] = t->vht[5] = mt76x2_rate_power_val(val); - t->vht[6] = t->vht[7] = mt76x2_rate_power_val(val >> 8); + t->vht[4] = t->vht[5] = mt76x02_rate_power_val(val); + t->vht[6] = t->vht[7] = mt76x02_rate_power_val(val >> 8); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_VHT_MCS8); if (!is_5ghz) val >>= 8; - t->vht[8] = t->vht[9] = mt76x2_rate_power_val(val >> 8); + t->vht[8] = t->vht[9] = mt76x02_rate_power_val(val >> 8); memcpy(t->stbc, t->ht, sizeof(t->stbc[0]) * 8); t->stbc[8] = t->vht[8]; @@ -402,7 +385,7 @@ mt76x2_get_power_info_2g(struct mt76x2_dev *dev, struct mt76x2_tx_power_info *t, t->chain[chain].tssi_slope = data[0]; t->chain[chain].tssi_offset = data[1]; t->chain[chain].target_power = data[2]; - t->chain[chain].delta = mt76x2_sign_extend_optional(data[delta_idx], 7); + t->chain[chain].delta = mt76x02_sign_extend_optional(data[delta_idx], 7); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RF_2G_TSSI_OFF_TXPOWER); t->target_power = val >> 8; @@ -451,7 +434,7 @@ mt76x2_get_power_info_5g(struct mt76x2_dev *dev, struct mt76x2_tx_power_info *t, t->chain[chain].tssi_slope = data[0]; t->chain[chain].tssi_offset = data[1]; t->chain[chain].target_power = data[2]; - t->chain[chain].delta = mt76x2_sign_extend_optional(data[delta_idx], 7); + t->chain[chain].delta = mt76x02_sign_extend_optional(data[delta_idx], 7); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RF_2G_RX_HIGH_GAIN); t->target_power = val & 0xff; @@ -485,8 +468,8 @@ void mt76x2_get_power_info(struct mt76x2_dev *dev, !mt76x02_field_valid(t->target_power)) t->target_power = t->chain[0].target_power; - t->delta_bw40 = mt76x2_rate_power_val(bw40); - t->delta_bw80 = mt76x2_rate_power_val(bw80); + t->delta_bw40 = mt76x02_rate_power_val(bw40); + t->delta_bw80 = mt76x02_rate_power_val(bw80); } EXPORT_SYMBOL_GPL(mt76x2_get_power_info); From patchwork Sat Sep 22 11:45:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10611389 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 7E06E913 for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E1492C0E5 for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62C8B2C0D3; Sat, 22 Sep 2018 11:49: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=-6.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,TVD_SUBJ_WIPE_DEBT 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 7A3092BFC4 for ; Sat, 22 Sep 2018 11:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728934AbeIVRjL (ORCPT ); Sat, 22 Sep 2018 13:39:11 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38690 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbeIVRjL (ORCPT ); Sat, 22 Sep 2018 13:39:11 -0400 Received: by mail-wm1-f65.google.com with SMTP id t25-v6so5719404wmi.3 for ; Sat, 22 Sep 2018 04:45: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; bh=LBP1Pz9gZt+xF7SGqklyEy5UuAJwmZoOl69yReGZ05U=; b=G6PU1ZzJdosW8sgbS1012fmCHEsmKufgreYWmRN8/SAW95rsr0E19VmWIMRzb9U16P vGKcIt15QQZx/1+UGV0unWwgy/cdhWLkOEiR/MBxYIlBmH+aflUeN3bW5I11Xk7rrGmZ IOgoEttcR177OEYmPwcoZC8y+YOVWsSrxJQRVOlRXZpXVXNuTqU6+HkHUkHOJ3d8NlkU aqn0DP8Rg9lZE7ATJ6DoHtvvuBC1N+XqmV+m/mHK68c71XGq6KqiS6599xu7VL7GO6oL +dHAYdybg8hKqghFK17OE1ZR02k7NnK6N/pe7eJfXf7Sidff7Kvz7mM8EzVEbM8HiJQX znrQ== X-Gm-Message-State: ABuFfoiKDBxfLgto2XmZ9WCk78cT4zByWvG9DyU5zWF/d7OdSQVKhqVZ QuRRHCnrOv96bzvGDQo67GVNoDk5BZI= X-Google-Smtp-Source: ANB0VdbAA4CuDaeEqTpFvLFMTsmA7aPDDU909dIpxnQituJiwwalY2YTlgtSB8OTgK68KI0BI1eA7Q== X-Received: by 2002:a1c:e157:: with SMTP id y84-v6mr1334433wmg.22.1537616752303; Sat, 22 Sep 2018 04:45:52 -0700 (PDT) Received: from localhost.localdomain ([151.66.72.6]) by smtp.gmail.com with ESMTPSA id u4-v6sm19600748wro.47.2018.09.22.04.45.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Sep 2018 04:45:51 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH 5/9] mt76x0: remove mt76x0_phy_set_tx_power and mt76x0_extra_power_over_mac Date: Sat, 22 Sep 2018 13:45:33 +0200 Message-Id: <20180922114537.24004-6-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 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 Remove mt76x0_extra_power_over_mac and mt76x0_phy_set_tx_power routines since they are not actually used and tx power handling will be unified with mt76x2 driver Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index c3db4c1cd4fe..99446fc4503e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -547,44 +547,6 @@ mt76x0_phy_set_chan_bbp_params(struct mt76x0_dev *dev, u8 channel, u16 rf_bw_ban } } -#if 0 -static void -mt76x0_extra_power_over_mac(struct mt76x0_dev *dev) -{ - u32 val; - - val = ((mt76_rr(dev, MT_TX_PWR_CFG_1) & 0x00003f00) >> 8); - val |= ((mt76_rr(dev, MT_TX_PWR_CFG_2) & 0x00003f00) << 8); - mt76_wr(dev, MT_TX_PWR_CFG_7, val); - - /* TODO: fix VHT */ - val = ((mt76_rr(dev, MT_TX_PWR_CFG_3) & 0x0000ff00) >> 8); - mt76_wr(dev, MT_TX_PWR_CFG_8, val); - - val = ((mt76_rr(dev, MT_TX_PWR_CFG_4) & 0x0000ff00) >> 8); - mt76_wr(dev, MT_TX_PWR_CFG_9, val); -} - -static void -mt76x0_phy_set_tx_power(struct mt76x0_dev *dev, u8 channel, u8 rf_bw_band) -{ - u32 val; - int i; - int bw = (rf_bw_band & RF_BW_20) ? 0 : 1; - - for (i = 0; i < 4; i++) { - if (channel <= 14) - val = dev->ee->tx_pwr_cfg_2g[i][bw]; - else - val = dev->ee->tx_pwr_cfg_5g[i][bw]; - - mt76_wr(dev, MT_TX_PWR_CFG_0 + 4*i, val); - } - - mt76x0_extra_power_over_mac(dev); -} -#endif - static void mt76x0_bbp_set_bw(struct mt76x0_dev *dev, enum nl80211_chan_width width) { From patchwork Sat Sep 22 11:45:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10611399 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 E28F7913 for ; Sat, 22 Sep 2018 11:49:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEC9E2BF9B for ; Sat, 22 Sep 2018 11:49:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C30FB2BFC4; Sat, 22 Sep 2018 11:49:02 +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 BAA312BFE7 for ; Sat, 22 Sep 2018 11:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729071AbeIVRjO (ORCPT ); Sat, 22 Sep 2018 13:39:14 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53706 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbeIVRjN (ORCPT ); Sat, 22 Sep 2018 13:39:13 -0400 Received: by mail-wm1-f68.google.com with SMTP id b19-v6so5436863wme.3 for ; Sat, 22 Sep 2018 04:45: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; bh=FGFgEM4kqFD/1lKJBxeGENmNNA6PPeKv8vofC+6WMfE=; b=Z0dLcJckUHLb9KgfFuvbVGSRoHg40t/OByDk/nzkJLapvgTNktwcEJYXsmza2M8fQQ ld+3MtF6UcHQVyZLvCopGUj6G9GphTOVZxs3Hz2pTpsffie68FeZ9A8+ABy+5wrjGZUa BL+CN9IXl0K1UdBVZHfzfn5IL/xXn8QLUr7TfALDCOiVWkl6Ez6kDm0kO60XVsAcD5K9 TuNwX0nZ+xyZOhRI9y89ETo3DEbLYePmYnbkV5tCS1tLRGFHcEbH9SRl5pGTVzahtrjA zxBMky9Ke457Zf9JAfma52FZ0P2OL0LDcq44RQ9A9S9sW7j5SFWyydMgDelwQkc2hQny VvAw== X-Gm-Message-State: APzg51BQa7xrNpla5txakCOX0VCCkOCu4aM1IfrtfvflTsS3iTuQP2zm Ffc1IznAJTj7HoEvYAta+ybAKg== X-Google-Smtp-Source: ANB0Vdac6uqbHjbCPnYome+RRhlEZe5KDd5teMg9IorPoHKElyjObMM/jScj5K2TKFjonemiguSVVA== X-Received: by 2002:a1c:a1c6:: with SMTP id k189-v6mr1345126wme.93.1537616753707; Sat, 22 Sep 2018 04:45:53 -0700 (PDT) Received: from localhost.localdomain ([151.66.72.6]) by smtp.gmail.com with ESMTPSA id u4-v6sm19600748wro.47.2018.09.22.04.45.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Sep 2018 04:45:52 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH 6/9] mt76x0: remove eeprom dependency from mt76x0_set_tx_power_per_rate Date: Sat, 22 Sep 2018 13:45:34 +0200 Message-Id: <20180922114537.24004-7-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 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 In order to unify eeprom parsing between mt76x0 and mt76x2 drivers, remove eeprom pointer dependency from mt76x0_set_tx_power_per_rate. Moreover use mt76_rate_power to store power vs rate calibration data. Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 32 ++-- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 142 +++++++++--------- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 32 +--- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 3 +- .../wireless/mediatek/mt76/mt76x02_eeprom.h | 4 +- 5 files changed, 102 insertions(+), 111 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index 39c2c846f808..eb7e0db61e56 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -118,19 +118,6 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) for (i = 0; i < 58; i++) seq_printf(file, "\t%d chan:%d pwr:%d\n", i, i, dev->ee->tx_pwr_per_chan[i]); - - seq_puts(file, "Per rate power 2GHz:\n"); - for (i = 0; i < 5; i++) - seq_printf(file, "\t %d bw20:%d bw40:%d\n", - i, dev->ee->tx_pwr_cfg_2g[i][0], - dev->ee->tx_pwr_cfg_5g[i][1]); - - seq_puts(file, "Per rate power 5GHz:\n"); - for (i = 0; i < 5; i++) - seq_printf(file, "\t %d bw20:%d bw40:%d\n", - i, dev->ee->tx_pwr_cfg_5g[i][0], - dev->ee->tx_pwr_cfg_5g[i][1]); - return 0; } @@ -147,6 +134,23 @@ static const struct file_operations fops_eeprom_param = { .release = single_release, }; +static int mt76x0_read_txpower(struct seq_file *file, void *data) +{ + struct mt76x0_dev *dev = dev_get_drvdata(file->private); + + mt76_seq_puts_array(file, "CCK", dev->mt76.rate_power.cck, + ARRAY_SIZE(dev->mt76.rate_power.cck)); + mt76_seq_puts_array(file, "OFDM", dev->mt76.rate_power.ofdm, + ARRAY_SIZE(dev->mt76.rate_power.ofdm)); + mt76_seq_puts_array(file, "STBC", dev->mt76.rate_power.stbc, + ARRAY_SIZE(dev->mt76.rate_power.stbc)); + mt76_seq_puts_array(file, "HT", dev->mt76.rate_power.ht, + ARRAY_SIZE(dev->mt76.rate_power.ht)); + mt76_seq_puts_array(file, "VHT", dev->mt76.rate_power.vht, + ARRAY_SIZE(dev->mt76.rate_power.vht)); + return 0; +} + void mt76x0_init_debugfs(struct mt76x0_dev *dev) { struct dentry *dir; @@ -161,4 +165,6 @@ void mt76x0_init_debugfs(struct mt76x0_dev *dev) debugfs_create_file("ampdu_stat", S_IRUSR, dir, dev, &fops_ampdu_stat); debugfs_create_file("eeprom_param", S_IRUSR, dir, dev, &fops_eeprom_param); + debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir, + mt76x0_read_txpower); } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index f9d917a7f3f5..22837d7191d3 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -20,6 +20,7 @@ #include #include "mt76x0.h" #include "eeprom.h" +#include "../mt76x02_phy.h" #define MT_MAP_READS DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16) static int @@ -125,82 +126,88 @@ void mt76x0_read_rx_gain(struct mt76x0_dev *dev) } } -static u32 -calc_bw40_power_rate(u32 value, int delta) +static s8 mt76x0_get_delta(struct mt76_dev *dev) { - u32 ret = 0; - int i, tmp; - - for (i = 0; i < 4; i++) { - tmp = s6_to_int((value >> i*8) & 0xff) + delta; - ret |= (u32)(int_to_s6(tmp)) << i*8; - } + struct cfg80211_chan_def *chandef = &dev->chandef; + u8 val; - return ret; -} + if (mt76x02_tssi_enabled(dev)) + return 0; -static s8 -get_delta(u8 val) -{ - s8 ret; + if (chandef->width == NL80211_CHAN_WIDTH_80) { + val = mt76x02_eeprom_get(dev, MT_EE_5G_TARGET_POWER) >> 8; + } else if (chandef->width == NL80211_CHAN_WIDTH_40) { + u16 data; - if (!mt76x02_field_valid(val) || !(val & BIT(7))) + data = mt76x02_eeprom_get(dev, MT_EE_TX_POWER_DELTA_BW40); + if (chandef->chan->band == NL80211_BAND_5GHZ) + val = data >> 8; + else + val = data; + } else { return 0; + } - ret = val & 0x1f; - if (ret > 8) - ret = 8; - if (val & BIT(6)) - ret = -ret; - - return ret; + return mt76x02_rate_power_val(val); } -static void -mt76x0_set_tx_power_per_rate(struct mt76x0_dev *dev, u8 *eeprom) +void mt76x0_get_tx_power_per_rate(struct mt76x0_dev *dev) { - s8 bw40_delta_2g, bw40_delta_5g; - u32 val; - int i; - - bw40_delta_2g = get_delta(eeprom[MT_EE_TX_POWER_DELTA_BW40]); - bw40_delta_5g = get_delta(eeprom[MT_EE_TX_POWER_DELTA_BW40 + 1]); - - for (i = 0; i < 5; i++) { - val = get_unaligned_le32(eeprom + MT_EE_TX_POWER_BYRATE(i)); - - /* Skip last 16 bits. */ - if (i == 4) - val &= 0x0000ffff; - - dev->ee->tx_pwr_cfg_2g[i][0] = val; - dev->ee->tx_pwr_cfg_2g[i][1] = calc_bw40_power_rate(val, bw40_delta_2g); - } - - /* Reading per rate tx power for 5 GHz band is a bit more complex. Note - * we mix 16 bit and 32 bit reads and sometimes do shifts. - */ - val = get_unaligned_le16(eeprom + 0x120); - val <<= 16; - dev->ee->tx_pwr_cfg_5g[0][0] = val; - dev->ee->tx_pwr_cfg_5g[0][1] = calc_bw40_power_rate(val, bw40_delta_5g); - - val = get_unaligned_le32(eeprom + 0x122); - dev->ee->tx_pwr_cfg_5g[1][0] = val; - dev->ee->tx_pwr_cfg_5g[1][1] = calc_bw40_power_rate(val, bw40_delta_5g); - - val = get_unaligned_le16(eeprom + 0x126); - dev->ee->tx_pwr_cfg_5g[2][0] = val; - dev->ee->tx_pwr_cfg_5g[2][1] = calc_bw40_power_rate(val, bw40_delta_5g); - - val = get_unaligned_le16(eeprom + 0xec); - val <<= 16; - dev->ee->tx_pwr_cfg_5g[3][0] = val; - dev->ee->tx_pwr_cfg_5g[3][1] = calc_bw40_power_rate(val, bw40_delta_5g); - - val = get_unaligned_le16(eeprom + 0xee); - dev->ee->tx_pwr_cfg_5g[4][0] = val; - dev->ee->tx_pwr_cfg_5g[4][1] = calc_bw40_power_rate(val, bw40_delta_5g); + struct ieee80211_channel *chan = dev->mt76.chandef.chan; + bool is_2ghz = chan->band == NL80211_BAND_2GHZ; + struct mt76_rate_power *t = &dev->mt76.rate_power; + s8 delta = mt76x0_get_delta(&dev->mt76); + u16 val, addr; + + memset(t, 0, sizeof(*t)); + + /* cck 1M, 2M, 5.5M, 11M */ + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_BYRATE_BASE); + t->cck[0] = t->cck[1] = s6_to_s8(val); + t->cck[2] = t->cck[3] = s6_to_s8(val >> 8); + + /* ofdm 6M, 9M, 12M, 18M */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 2 : 0x120; + val = mt76x02_eeprom_get(&dev->mt76, addr); + t->ofdm[0] = t->ofdm[1] = s6_to_s8(val); + t->ofdm[2] = t->ofdm[3] = s6_to_s8(val >> 8); + + /* ofdm 24M, 36M, 48M, 54M */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 4 : 0x122; + val = mt76x02_eeprom_get(&dev->mt76, addr); + t->ofdm[4] = t->ofdm[5] = s6_to_s8(val); + t->ofdm[6] = t->ofdm[7] = s6_to_s8(val >> 8); + + /* ht-vht mcs 1ss 0, 1, 2, 3 */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 6 : 0x124; + val = mt76x02_eeprom_get(&dev->mt76, addr); + t->ht[0] = t->ht[1] = t->vht[0] = t->vht[1] = s6_to_s8(val); + t->ht[2] = t->ht[3] = t->vht[2] = t->vht[3] = s6_to_s8(val >> 8); + + /* ht-vht mcs 1ss 4, 5, 6 */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 8 : 0x126; + val = mt76x02_eeprom_get(&dev->mt76, addr); + t->ht[4] = t->ht[5] = t->vht[4] = t->vht[5] = s6_to_s8(val); + t->ht[6] = t->vht[6] = s6_to_s8(val >> 8); + + /* ht-vht mcs 1ss 0, 1, 2, 3 stbc */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 14 : 0xec; + val = mt76x02_eeprom_get(&dev->mt76, addr); + t->stbc[0] = t->stbc[1] = s6_to_s8(val); + t->stbc[2] = t->stbc[3] = s6_to_s8(val >> 8); + + /* ht-vht mcs 1ss 4, 5, 6 stbc */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 16 : 0xee; + val = mt76x02_eeprom_get(&dev->mt76, addr); + t->stbc[4] = t->stbc[5] = s6_to_s8(val); + t->stbc[6] = t->stbc[7] = s6_to_s8(val >> 8); + + /* vht mcs 8, 9 5GHz */ + val = mt76x02_eeprom_get(&dev->mt76, 0x132); + t->vht[7] = s6_to_s8(val); + t->vht[8] = s6_to_s8(val >> 8); + + mt76x02_add_rate_power_offset(t, delta); } static void @@ -271,7 +278,6 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x0_set_temp_offset(dev); dev->chainmask = 0x0101; - mt76x0_set_tx_power_per_rate(dev, eeprom); mt76x0_set_tx_power_per_chan(dev, eeprom); out: diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index 8006d08cba45..d556ee37fa14 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -37,41 +37,21 @@ struct mt76x0_caldata { }; struct mt76x0_eeprom_params { - /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ - u32 tx_pwr_cfg_2g[5][2]; - u32 tx_pwr_cfg_5g[5][2]; u8 tx_pwr_per_chan[58]; }; int mt76x0_eeprom_init(struct mt76x0_dev *dev); void mt76x0_read_rx_gain(struct mt76x0_dev *dev); +void mt76x0_get_tx_power_per_rate(struct mt76x0_dev *dev); -static inline u32 s6_validate(u32 reg) +static inline s8 s6_to_s8(u32 val) { - WARN_ON(reg & ~GENMASK(5, 0)); - return reg & GENMASK(5, 0); -} - -static inline int s6_to_int(u32 reg) -{ - int s6; - - s6 = s6_validate(reg); - if (s6 & BIT(5)) - s6 -= BIT(6); - - return s6; -} - -static inline u32 int_to_s6(int val) -{ - if (val < -0x20) - return 0x20; - if (val > 0x1f) - return 0x1f; + s8 ret = val & GENMASK(5, 0); - return val & 0x3f; + if (ret & BIT(5)) + ret -= BIT(6); + return ret; } #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 99446fc4503e..dea68f5d91f6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -641,6 +641,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev, freq1 = chandef->center_freq1; channel = chandef->chan->hw_value; rf_bw_band = (channel <= 14) ? RF_G_BAND : RF_A_BAND; + dev->mt76.chandef = *chandef; switch (chandef->width) { case NL80211_CHAN_WIDTH_40: @@ -678,6 +679,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev, mt76x0_phy_set_band(dev, chandef->chan->band); mt76x0_phy_set_chan_rf_params(dev, channel, rf_bw_band); + mt76x0_get_tx_power_per_rate(dev); mt76x0_read_rx_gain(dev); /* set Japan Tx filter at channel 14 */ @@ -699,7 +701,6 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev, mt76x0_phy_set_chan_pwr(dev, channel); - dev->mt76.chandef = *chandef; return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index c3d8920a8127..b45e2afeadd0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -74,6 +74,7 @@ enum mt76x02_eeprom_field { MT_EE_2G_TARGET_POWER = 0x0d0, MT_EE_TEMP_OFFSET = 0x0d1, + MT_EE_5G_TARGET_POWER = 0x0d2, MT_EE_TSSI_BOUND1 = 0x0d4, MT_EE_TSSI_BOUND2 = 0x0d6, MT_EE_TSSI_BOUND3 = 0x0d8, @@ -121,9 +122,6 @@ enum mt76x02_eeprom_field { #define MT_EE_NIC_CONF_2_TEMP_DISABLE BIT(11) #define MT_EE_NIC_CONF_2_COEX_METHOD GENMASK(15, 13) -#define MT_EE_TX_POWER_BYRATE(x) (MT_EE_TX_POWER_BYRATE_BASE + \ - (x) * 4) - #define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \ MT_EE_USAGE_MAP_START + 1) From patchwork Sat Sep 22 11:45:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10611395 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 2B704913 for ; Sat, 22 Sep 2018 11:49:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B5F32BF83 for ; Sat, 22 Sep 2018 11:49:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FFB12BF9B; Sat, 22 Sep 2018 11:49:02 +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 DADA72BFF4 for ; Sat, 22 Sep 2018 11:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729095AbeIVRjO (ORCPT ); Sat, 22 Sep 2018 13:39:14 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37940 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729017AbeIVRjO (ORCPT ); Sat, 22 Sep 2018 13:39:14 -0400 Received: by mail-wr1-f68.google.com with SMTP id j8-v6so11494950wrw.5 for ; Sat, 22 Sep 2018 04:45: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; bh=D6R8pO6z6VENmCIkAs0V9qyn7NYFkX+98aBl1Z7SkmE=; b=dsDQG0NsLj5zCfsEsnjSsSMtuvo2JoOfohudLeGBcMLrJS/8t2sLnjcKgw0KVj/pSd 1Kr9iYhGC7a8MzgwKCmOHwhBRX5qH90uXV2Q8KWuiPPnMRc+pHMRysKwqqQEi3l1WBN1 1FH7fdUYHZ33mHMMxKgw9Dz63QYKHRHxRLgooyxQdP7L4SlqqDazKi3aNF0jbNvASRv0 9u9APKPl67vsON/Bgq5XNYNTyz2xzVFoOFu8MF6uzteMaVBODy9s/TEF3zK7+IQqPXmf xfiiyXFbLXGwMSyMVm1NuhdXCNFEqbwA99zRSllEApHupVgcCDf4dU0GzynYLt88nuK0 c9ag== X-Gm-Message-State: ABuFfoh140jvjfWNSkAghp0JcaoFxVA0splNFQaFAYoo8YXonhTXWfmr 3bROdYa6v5y3LQ0lU+vreuvp4UFr6r8= X-Google-Smtp-Source: ACcGV63oVQDrHDBPDoDL79HLPqyAeIzDOKkPXnzo3eWLFfMWffD6ZCCIJIITtzQW3u+D7ws2DRY67Q== X-Received: by 2002:adf:a41c:: with SMTP id d28-v6mr1689746wra.121.1537616754835; Sat, 22 Sep 2018 04:45:54 -0700 (PDT) Received: from localhost.localdomain ([151.66.72.6]) by smtp.gmail.com with ESMTPSA id u4-v6sm19600748wro.47.2018.09.22.04.45.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Sep 2018 04:45:54 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH 7/9] mt76x0: remove eeprom dependency from mt76x0_get_power_info Date: Sat, 22 Sep 2018 13:45:35 +0200 Message-Id: <20180922114537.24004-8-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 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 In order to unify eeprom parsing between mt76x0 and mt76x2 drivers, remove eeprom pointer dependency from mt76x0_get_power_info routine. Remove mt76x0_eeprom_params since it is now an empty structure Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 5 - .../wireless/mediatek/mt76/mt76x0/eeprom.c | 109 +++++++++++------- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 11 +- .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 1 - .../net/wireless/mediatek/mt76/mt76x0/phy.c | 32 ++--- 5 files changed, 77 insertions(+), 81 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index eb7e0db61e56..75484cd0c9de 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -100,7 +100,6 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) { struct mt76x0_dev *dev = file->private; u16 val; - int i; seq_printf(file, "RF freq offset: %hhx\n", dev->caldata.freq_offset); @@ -114,10 +113,6 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) seq_printf(file, "Power Amplifier type %lx\n", val & MT_EE_NIC_CONF_0_PA_TYPE); - seq_puts(file, "Per channel power:\n"); - for (i = 0; i < 58; i++) - seq_printf(file, "\t%d chan:%d pwr:%d\n", i, i, - dev->ee->tx_pwr_per_chan[i]); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 22837d7191d3..ef3b44202efe 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -210,38 +210,71 @@ void mt76x0_get_tx_power_per_rate(struct mt76x0_dev *dev) mt76x02_add_rate_power_offset(t, delta); } -static void -mt76x0_set_tx_power_per_chan(struct mt76x0_dev *dev, u8 *eeprom) +void mt76x0_get_power_info(struct mt76x0_dev *dev, u8 *info) { + struct mt76x0_chan_map { + u8 chan; + u8 offset; + } chan_map[] = { + { 2, 0 }, { 4, 1 }, { 6, 2 }, { 8, 3 }, + { 10, 4 }, { 12, 5 }, { 14, 6 }, { 38, 0 }, + { 44, 1 }, { 48, 2 }, { 54, 3 }, { 60, 4 }, + { 64, 5 }, { 102, 6 }, { 108, 7 }, { 112, 8 }, + { 118, 9 }, { 124, 10 }, { 128, 11 }, { 134, 12 }, + { 140, 13 }, { 151, 14 }, { 157, 15 }, { 161, 16 }, + { 167, 17 }, { 171, 18 }, { 173, 19 }, + }; + struct ieee80211_channel *chan = dev->mt76.chandef.chan; + u8 offset, addr; + u16 data; int i; - u8 tx_pwr; - for (i = 0; i < 14; i++) { - tx_pwr = eeprom[MT_EE_TX_POWER_DELTA_BW80 + i]; - if (tx_pwr <= 0x3f && tx_pwr > 0) - dev->ee->tx_pwr_per_chan[i] = tx_pwr; - else - dev->ee->tx_pwr_per_chan[i] = 5; + for (i = 0; i < ARRAY_SIZE(chan_map); i++) { + if (chan_map[i].chan <= chan->hw_value) { + offset = chan_map[i].offset; + break; + } } + if (i == ARRAY_SIZE(chan_map)) + offset = chan_map[0].offset; - for (i = 0; i < 40; i++) { - tx_pwr = eeprom[MT_EE_TX_POWER_0_GRP4_TSSI_SLOPE + 2 + i]; - if (tx_pwr <= 0x3f && tx_pwr > 0) - dev->ee->tx_pwr_per_chan[14 + i] = tx_pwr; - else - dev->ee->tx_pwr_per_chan[14 + i] = 5; + if (chan->band == NL80211_BAND_2GHZ) { + addr = MT_EE_TX_POWER_DELTA_BW80 + offset; + } else { + switch (chan->hw_value) { + case 58: + offset = 8; + break; + case 106: + offset = 14; + break; + case 112: + offset = 20; + break; + case 155: + offset = 30; + break; + default: + break; + } + addr = MT_EE_TX_POWER_0_GRP4_TSSI_SLOPE + 2 + offset; } - dev->ee->tx_pwr_per_chan[54] = dev->ee->tx_pwr_per_chan[22]; - dev->ee->tx_pwr_per_chan[55] = dev->ee->tx_pwr_per_chan[28]; - dev->ee->tx_pwr_per_chan[56] = dev->ee->tx_pwr_per_chan[34]; - dev->ee->tx_pwr_per_chan[57] = dev->ee->tx_pwr_per_chan[44]; + data = mt76x02_eeprom_get(&dev->mt76, addr); + + info[0] = data; + if (!info[0] || info[0] > 0x3f) + info[0] = 5; + + info[1] = data >> 8; + if (!info[1] || info[1] > 0x3f) + info[1] = 5; } -int -mt76x0_eeprom_init(struct mt76x0_dev *dev) +int mt76x0_eeprom_init(struct mt76x0_dev *dev) { - u8 *eeprom; + u8 version, fae; + u16 data; int ret; ret = mt76x0_efuse_physical_size_check(dev); @@ -252,37 +285,31 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) if (ret < 0) return ret; - dev->ee = devm_kzalloc(dev->mt76.dev, sizeof(*dev->ee), GFP_KERNEL); - if (!dev->ee) - return -ENOMEM; - - eeprom = kmalloc(MT76X0_EEPROM_SIZE, GFP_KERNEL); - if (!eeprom) - return -ENOMEM; - - ret = mt76x02_get_efuse_data(&dev->mt76, 0, eeprom, + ret = mt76x02_get_efuse_data(&dev->mt76, 0, dev->mt76.eeprom.data, MT76X0_EEPROM_SIZE, MT_EE_READ); if (ret) - goto out; + return ret; + + data = mt76x02_eeprom_get(&dev->mt76, MT_EE_VERSION); + version = data >> 8; + fae = data; - if (eeprom[MT_EE_VERSION + 1] > MT76X0U_EE_MAX_VER) + if (version > MT76X0U_EE_MAX_VER) dev_warn(dev->mt76.dev, "Warning: unsupported EEPROM version %02hhx\n", - eeprom[MT_EE_VERSION + 1]); + version); dev_info(dev->mt76.dev, "EEPROM ver:%02hhx fae:%02hhx\n", - eeprom[MT_EE_VERSION + 1], eeprom[MT_EE_VERSION]); + version, fae); - mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR); + mt76x02_mac_setaddr(&dev->mt76, + dev->mt76.eeprom.data + MT_EE_MAC_ADDR); mt76x0_set_chip_cap(dev); mt76x0_set_freq_offset(dev); mt76x0_set_temp_offset(dev); - dev->chainmask = 0x0101; - mt76x0_set_tx_power_per_chan(dev, eeprom); + dev->chainmask = 0x0101; -out: - kfree(eeprom); - return ret; + return 0; } MODULE_LICENSE("Dual BSD/GPL"); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index d556ee37fa14..4e1fafa5b8c3 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -23,11 +23,6 @@ struct mt76x0_dev; #define MT76X0U_EE_MAX_VER 0x0c #define MT76X0_EEPROM_SIZE 512 -struct reg_channel_bounds { - u8 start; - u8 num; -}; - struct mt76x0_caldata { s8 rssi_offset[2]; s8 lna_gain; @@ -36,14 +31,10 @@ struct mt76x0_caldata { u8 freq_offset; }; -struct mt76x0_eeprom_params { - - u8 tx_pwr_per_chan[58]; -}; - int mt76x0_eeprom_init(struct mt76x0_dev *dev); void mt76x0_read_rx_gain(struct mt76x0_dev *dev); void mt76x0_get_tx_power_per_rate(struct mt76x0_dev *dev); +void mt76x0_get_power_info(struct mt76x0_dev *dev, u8 *info); static inline s8 s6_to_s8(u32 val) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index 99d48fa96fd9..101332a35f40 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -89,7 +89,6 @@ struct mt76x0_dev { const u16 *beacon_offsets; - struct mt76x0_eeprom_params *ee; struct mt76x0_caldata caldata; struct mutex reg_atomic_mutex; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index dea68f5d91f6..9c9c55cc05e9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -578,31 +578,15 @@ mt76x0_bbp_set_bw(struct mt76x0_dev *dev, enum nl80211_chan_width width) mt76x02_mcu_function_select(&dev->mt76, BW_SETTING, bw, false); } -static void -mt76x0_phy_set_chan_pwr(struct mt76x0_dev *dev, u8 channel) +static void mt76x0_phy_set_chan_pwr(struct mt76x0_dev *dev) { - static const int mt76x0_tx_pwr_ch_list[] = { - 1,2,3,4,5,6,7,8,9,10,11,12,13,14, - 36,38,40,44,46,48,52,54,56,60,62,64, - 100,102,104,108,110,112,116,118,120,124,126,128,132,134,136,140, - 149,151,153,157,159,161,165,167,169,171,173, - 42,58,106,122,155 - }; - int i; - u32 val; - - for (i = 0; i < ARRAY_SIZE(mt76x0_tx_pwr_ch_list); i++) - if (mt76x0_tx_pwr_ch_list[i] == channel) - break; - - if (WARN_ON(i == ARRAY_SIZE(mt76x0_tx_pwr_ch_list))) - return; + u8 info[2]; - val = mt76_rr(dev, MT_TX_ALC_CFG_0); - val &= ~0x3f3f; - val |= dev->ee->tx_pwr_per_chan[i]; - val |= 0x2f2f << 16; - mt76_wr(dev, MT_TX_ALC_CFG_0, val); + mt76x0_get_power_info(dev, info); + mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_0, + info[0]); + mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_1, + info[1]); } static int @@ -699,7 +683,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev, if (scan) mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXDCOC, 1, false); - mt76x0_phy_set_chan_pwr(dev, channel); + mt76x0_phy_set_chan_pwr(dev); return 0; } From patchwork Sat Sep 22 11:45:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10611391 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 990CE17EE for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86F5B2BF83 for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 779832C0F8; Sat, 22 Sep 2018 11:49: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 074A32BF83 for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729134AbeIVRjP (ORCPT ); Sat, 22 Sep 2018 13:39:15 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52460 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729025AbeIVRjO (ORCPT ); Sat, 22 Sep 2018 13:39:14 -0400 Received: by mail-wm1-f66.google.com with SMTP id l7-v6so628322wme.2 for ; Sat, 22 Sep 2018 04:45:56 -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; bh=gLQRHTgWVcC5I08/zqlUIPb6owsNlLZcHJ7qnRtPx1o=; b=uXzLV/i19spWbk26rHNNdENcPTCaUu/J8FgG54ZEkdqCvuoWnICTdTrNm/s5P02QkP wtx0sI5zYE0itI/98cs2WiH9xydSDDrddUzIHZZSWH6oym4MSkj7nmzXzxx/qtDgYUSk 48DyYxgqmKfpxrrwD2VgSvzrGOa2lWonEX46pf61SF7H5QzcD9n2oBcoo1SLJfIL7j/z dyh0ZNw96DFYr9bGwRCOU6KUCNL3uomWOHG9JTJ0VfWCnGC3Lg/2SdOMfHt0wwM2mra1 7XK0tBJO9T+ANgXdSZPsyfrOD58hM4bDL6lCGYl62/id68GQ43C1ewmJfUPO6pFjorU1 39Ag== X-Gm-Message-State: APzg51C7kJFQj9EezVDG5rng0GyjFJqpHsufjLn61k7c8YGyzg3WzFsG iWjNnQE96/XqOuvLc0FXgp6l3h4SrWU= X-Google-Smtp-Source: ACcGV60M93RQEJItfsjqGTNkqJtAVR41QRJBr0TQJJ9Imhu/IzTXtUF71GDPhE/h9f8AJx1tBo4xog== X-Received: by 2002:a1c:4156:: with SMTP id o83-v6mr1272786wma.114.1537616755887; Sat, 22 Sep 2018 04:45:55 -0700 (PDT) Received: from localhost.localdomain ([151.66.72.6]) by smtp.gmail.com with ESMTPSA id u4-v6sm19600748wro.47.2018.09.22.04.45.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Sep 2018 04:45:55 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH 8/9] mt76x0: use shared debugfs implementation Date: Sat, 22 Sep 2018 13:45:36 +0200 Message-Id: <20180922114537.24004-9-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 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 mt76 shared debugfs implementation and remove duplicated code in mt76x0 driver Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 80 +------------------ .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 2 - 2 files changed, 1 insertion(+), 81 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index 75484cd0c9de..ddc1af626b3b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -18,26 +18,6 @@ #include "mt76x0.h" #include "eeprom.h" -static int -mt76_reg_set(void *data, u64 val) -{ - struct mt76x0_dev *dev = data; - - mt76_wr(dev, dev->debugfs_reg, val); - return 0; -} - -static int -mt76_reg_get(void *data, u64 *val) -{ - struct mt76x0_dev *dev = data; - - *val = mt76_rr(dev, dev->debugfs_reg); - return 0; -} - -DEFINE_SIMPLE_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set, "0x%08llx\n"); - static int mt76x0_ampdu_stat_read(struct seq_file *file, void *data) { @@ -95,71 +75,13 @@ static const struct file_operations fops_ampdu_stat = { .release = single_release, }; -static int -mt76x0_eeprom_param_read(struct seq_file *file, void *data) -{ - struct mt76x0_dev *dev = file->private; - u16 val; - - seq_printf(file, "RF freq offset: %hhx\n", - dev->caldata.freq_offset); - seq_printf(file, "RSSI offset: %hhx %hhx\n", - dev->caldata.rssi_offset[0], dev->caldata.rssi_offset[1]); - seq_printf(file, "Temperature offset: %hhx\n", - dev->caldata.temp_offset); - seq_printf(file, "LNA gain: %x\n", dev->caldata.lna_gain); - - val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); - seq_printf(file, "Power Amplifier type %lx\n", - val & MT_EE_NIC_CONF_0_PA_TYPE); - - return 0; -} - -static int -mt76x0_eeprom_param_open(struct inode *inode, struct file *f) -{ - return single_open(f, mt76x0_eeprom_param_read, inode->i_private); -} - -static const struct file_operations fops_eeprom_param = { - .open = mt76x0_eeprom_param_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static int mt76x0_read_txpower(struct seq_file *file, void *data) -{ - struct mt76x0_dev *dev = dev_get_drvdata(file->private); - - mt76_seq_puts_array(file, "CCK", dev->mt76.rate_power.cck, - ARRAY_SIZE(dev->mt76.rate_power.cck)); - mt76_seq_puts_array(file, "OFDM", dev->mt76.rate_power.ofdm, - ARRAY_SIZE(dev->mt76.rate_power.ofdm)); - mt76_seq_puts_array(file, "STBC", dev->mt76.rate_power.stbc, - ARRAY_SIZE(dev->mt76.rate_power.stbc)); - mt76_seq_puts_array(file, "HT", dev->mt76.rate_power.ht, - ARRAY_SIZE(dev->mt76.rate_power.ht)); - mt76_seq_puts_array(file, "VHT", dev->mt76.rate_power.vht, - ARRAY_SIZE(dev->mt76.rate_power.vht)); - return 0; -} - void mt76x0_init_debugfs(struct mt76x0_dev *dev) { struct dentry *dir; - dir = debugfs_create_dir("mt76x0", dev->mt76.hw->wiphy->debugfsdir); + dir = mt76_register_debugfs(&dev->mt76); if (!dir) return; - debugfs_create_u32("regidx", S_IRUSR | S_IWUSR, dir, &dev->debugfs_reg); - debugfs_create_file("regval", S_IRUSR | S_IWUSR, dir, dev, - &fops_regval); debugfs_create_file("ampdu_stat", S_IRUSR, dir, dev, &fops_ampdu_stat); - debugfs_create_file("eeprom_param", S_IRUSR, dir, dev, - &fops_eeprom_param); - debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir, - mt76x0_read_txpower); } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index 101332a35f40..e0b349c921b1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -94,8 +94,6 @@ struct mt76x0_dev { struct mutex reg_atomic_mutex; struct mutex hw_atomic_mutex; - u32 debugfs_reg; - atomic_t avg_ampdu_len; /* Connection monitoring things */ From patchwork Sat Sep 22 11:45:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10611401 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 0466817EE for ; Sat, 22 Sep 2018 11:49:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E938F2BF9B for ; Sat, 22 Sep 2018 11:49:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D58272BFE9; Sat, 22 Sep 2018 11:49:02 +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 27A4A2C028 for ; Sat, 22 Sep 2018 11:49:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729183AbeIVRjQ (ORCPT ); Sat, 22 Sep 2018 13:39:16 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53709 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729078AbeIVRjQ (ORCPT ); Sat, 22 Sep 2018 13:39:16 -0400 Received: by mail-wm1-f67.google.com with SMTP id b19-v6so5436937wme.3 for ; Sat, 22 Sep 2018 04:45:57 -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; bh=de3jS57rJUMvOgMUjsapUIuSL5qL60iLNbV0PEACC5s=; b=McZq7sbKcLOuMFksgj4r3ircQyOxfuSs7cCZGXNllmMXUZTHkCfKrBODWv+Pnc507q +CrhgrR8ULRUxD0bYCOhciGTdZUskVb3sLAJiS3MSN1hVp8wsaTMSVi/ndgnUEIdCvXE d4y8zbBz96CMZ4ZQTr1EdTN6Q3R2CrvUkxAeCpJCsSU84LjusPvopkpwrsVQ3GvihE9r v5jdHtTPygjfEq70CVBIdRwxAZIhI07p8dppm/iTcI/NBbmRe83X6G7VlOQLSdiZoyGM WLV633HdvA089mDSkF4YU2aJIbX0HqSrqBtNJlWrltMUyYrQUu+pcJjrvVoKo33RFIQa qWbQ== X-Gm-Message-State: ABuFfoilMwz/0bXQDA1zU8xNybt8q+D62XfeM9vPOB/hFeVyfOvwq8G1 xR5/LVXb5UIgzohZdo7eT875L1jvptQ= X-Google-Smtp-Source: ANB0Vdbuc6WPtTLJOz7DjZKoksttMD9nLSOsXHYBhLjJBP9DDagQzIq464nNctu6muQ/b6ku2cU16w== X-Received: by 2002:a1c:a401:: with SMTP id n1-v6mr1391024wme.125.1537616756790; Sat, 22 Sep 2018 04:45:56 -0700 (PDT) Received: from localhost.localdomain ([151.66.72.6]) by smtp.gmail.com with ESMTPSA id u4-v6sm19600748wro.47.2018.09.22.04.45.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Sep 2018 04:45:56 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org Subject: [PATCH 9/9] mt76x0: phy: introduce mt76x0_phy_set_txpower routine Date: Sat, 22 Sep 2018 13:45:37 +0200 Message-Id: <20180922114537.24004-10-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 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_set_txpower routine in order to configure base and per rate tx power gain. Moreover take into account txpower_conf in order to limit the tx power gain according to the bound provided by mac80211 Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/main.c | 7 +++++++ .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 1 + .../net/wireless/mediatek/mt76/mt76x0/phy.c | 19 ++++++++++++------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c index c84e00abfac9..66e12802953c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/main.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/main.c @@ -66,6 +66,13 @@ static int mt76x0_config(struct ieee80211_hw *hw, u32 changed) ieee80211_wake_queues(hw); } + if (changed & IEEE80211_CONF_CHANGE_POWER) { + dev->mt76.txpower_conf = hw->conf.power_level * 2; + + if (test_bit(MT76_STATE_RUNNING, &dev->mt76.state)) + mt76x0_phy_set_txpower(dev); + } + mutex_unlock(&dev->mt76.mutex); return ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index e0b349c921b1..7e131241344b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -147,6 +147,7 @@ void mt76x0_phy_recalibrate_after_assoc(struct mt76x0_dev *dev); int mt76x0_phy_get_rssi(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi); void mt76x0_phy_con_cal_onoff(struct mt76x0_dev *dev, struct ieee80211_bss_conf *info); +void mt76x0_phy_set_txpower(struct mt76x0_dev *dev); /* MAC */ void mt76x0_mac_work(struct work_struct *work); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 9c9c55cc05e9..d11fcf6c8967 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -21,6 +21,7 @@ #include "phy.h" #include "initvals.h" #include "initvals_phy.h" +#include "../mt76x02_phy.h" #include @@ -578,15 +579,20 @@ mt76x0_bbp_set_bw(struct mt76x0_dev *dev, enum nl80211_chan_width width) mt76x02_mcu_function_select(&dev->mt76, BW_SETTING, bw, false); } -static void mt76x0_phy_set_chan_pwr(struct mt76x0_dev *dev) +void mt76x0_phy_set_txpower(struct mt76x0_dev *dev) { + struct mt76_rate_power *t = &dev->mt76.rate_power; u8 info[2]; mt76x0_get_power_info(dev, info); - mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_0, - info[0]); - mt76_rmw_field(dev, MT_TX_ALC_CFG_0, MT_TX_ALC_CFG_0_CH_INIT_1, - info[1]); + mt76x0_get_tx_power_per_rate(dev); + + mt76x02_add_rate_power_offset(t, info[0]); + mt76x02_limit_rate_power(t, dev->mt76.txpower_conf); + dev->mt76.txpower_cur = mt76x02_get_max_rate_power(t); + mt76x02_add_rate_power_offset(t, -info[0]); + + mt76x02_phy_set_txpower(&dev->mt76, info[0], info[1]); } static int @@ -663,7 +669,6 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev, mt76x0_phy_set_band(dev, chandef->chan->band); mt76x0_phy_set_chan_rf_params(dev, channel, rf_bw_band); - mt76x0_get_tx_power_per_rate(dev); mt76x0_read_rx_gain(dev); /* set Japan Tx filter at channel 14 */ @@ -683,7 +688,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev, if (scan) mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_RXDCOC, 1, false); - mt76x0_phy_set_chan_pwr(dev); + mt76x0_phy_set_txpower(dev); return 0; }