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; }