From patchwork Thu Sep 20 09:11:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607221 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 C497714BD for ; Thu, 20 Sep 2018 09:25:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2FE62CC06 for ; Thu, 20 Sep 2018 09:25:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6D512CDC1; Thu, 20 Sep 2018 09:25:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EB7F62CC06 for ; Thu, 20 Sep 2018 09:25:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=TsmY+h6+7bYUo6p3S26a+ozAPoorphMlNYlmDq69E/U=; b=FTYCyt1t+PeX10A1yiMYCf9mwi vZUUJWVVTjCi/vTt9mQxQ89UJKaaqQjg+5YSeCL1OyDmdvNs+H0Zwn2niJa8HvMk4y5Avj57Vl5KF t80U0R/Fc4ei+dUDCOymtGXuL8YMZk/oV2rmarqIdPSzdri7ICLtc2hnHFY59zHzOMYhqetje+NdF 33m+oKOjfVmA8mPR9Z82fwGpIYuOvVG9fs7y2K/AvuKO/tlt1gGCdAzvX8oiK+9AZZ2W4cJzTolKn H4IFwbG3hChTgTxE/6R1HcsUgJbOzNkhynOwOWiL8qssTIk743T8ygXnonl5GrwrnkYsJL3YeB6d9 7So74aQA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2vCr-0006IA-2H; Thu, 20 Sep 2018 09:25:05 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2vCn-0006BC-22 for linux-mediatek@bombadil.infradead.org; Thu, 20 Sep 2018 09:25:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=JrRqjB+6AoD0LVCIqg1g/PP7bL82hE7G8sdiyy53EjE=; b=F4le67FXssIld+UCK1cq0zM+C lYtruakQJBye9tmYnxYu3DzZDfccx7pQ1GE8So4Eh0amXoZBG5q7jh94MPdhLYy/7Pm13JujbUyzU T/HetbvrejOt+SS5n7UkxaunKjUY7we1ueYEK5RglZqv1U94D6txZzhBfQ2x5yaxWSFozUwzE+agq uRlvY8Zv/cqSKcHtR0aF2Lsj3uZcAQ1Z0GyrKNdHqA05+od9MfOd6bB8ywdaFC7rmBj92uB+RWtgY ZFaAPTg37URVUuFLoNF0aOMwMaTUtgI3a7cRNe4ZEdU1bdCst1JYBz/W85nffD69xa6e0J8nxIgMa rr4E8VMBg==; Received: from mail-wr1-f68.google.com ([209.85.221.68]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2v0x-0004A2-NQ for linux-mediatek@lists.infradead.org; Thu, 20 Sep 2018 09:12:49 +0000 Received: by mail-wr1-f68.google.com with SMTP id v17-v6so8579328wrr.9 for ; Thu, 20 Sep 2018 02:12:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JrRqjB+6AoD0LVCIqg1g/PP7bL82hE7G8sdiyy53EjE=; b=iLLSeBOvYC7lISUqxDjd4JCD6WBzhEI3QKIUPc0ffBGcfjSiuJaZ6K363r6JA2Z/mB zyrNvBV9iNx2hIs4BGg3Q/5O7zM/SZA1K17Zy2/TSQ62fwshKEcSMdmMbaPFj8OQnWch pDrdk79GPrZL93GS/BBxy59YsYkoZ8vr80oyF+OGW1r1k48sK1FJ4iPtD4y3n/0axosy qIwCTpmqv+51H6ym4R3EKQxYs9fODDcDgUotJCB7Uql4njy0hPthd6k3ZawJILNGFHDu NTRxlwqdVuBeuaXiXV6HUDemxJBWaxbIhMwMCsJx9Pwt+z8I/qKH6BWJKWY+kOuvudS0 UdfA== X-Gm-Message-State: APzg51AgTRRaqlGQL8ZDLlKBIXlceTp+67Nc0vgScwg6p2CKRHidDla6 ovxiMYtMfB7eUVAW8wsZYlYkOQ== X-Google-Smtp-Source: ANB0VdZ0uQzPhzUXQhoO55J0u+1f9NT23S+TBQZ+h8UvPNCiiqC3rIR0pEPofKbN8GRF6OQGsX8nRQ== X-Received: by 2002:adf:9f13:: with SMTP id l19-v6mr33029742wrf.206.1537434756695; Thu, 20 Sep 2018 02:12:36 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id 34-v6sm35501691wra.20.2018.09.20.02.12.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:36 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Subject: [PATCH 12/20] mt76x0: unify rssi_offset parsing Date: Thu, 20 Sep 2018 11:11:59 +0200 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180920_101247_813381_DA64D1BB X-CRM114-Status: GOOD ( 15.09 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sgruszka@redhat.com, linux-mediatek@lists.infradead.org, linux-wireless@vger.kernel.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Unify rssi_offset parsing with mt76x2 driver using eeprom utility routines available in mt76x02-lib module Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 7 +--- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 38 ++++--------------- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 3 +- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 12 +----- 4 files changed, 11 insertions(+), 49 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index 566ed0b61035..b6f467e7ee8c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -103,11 +103,8 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) int i; seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off); - seq_printf(file, "RSSI offset 2GHz: %hhx %hhx\n", - dev->ee->rssi_offset_2ghz[0], dev->ee->rssi_offset_2ghz[1]); - seq_printf(file, "RSSI offset 5GHz: %hhx %hhx %hhx\n", - dev->ee->rssi_offset_5ghz[0], dev->ee->rssi_offset_5ghz[1], - dev->ee->rssi_offset_5ghz[2]); + 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->ee->temp_off); seq_printf(file, "LNA gain: %x\n", dev->caldata.lna_gain); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 20a9f8fb20da..6c24274d23f4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -126,44 +126,21 @@ void mt76x0_read_rx_gain(struct mt76x0_dev *dev) { struct ieee80211_channel *chan = dev->mt76.chandef.chan; struct mt76x0_caldata *caldata = &dev->caldata; - s8 lna_5g[3], lna_2g; + s8 val, lna_5g[3], lna_2g; u16 rssi_offset; + int i; mt76x02_get_rx_gain(&dev->mt76, chan->band, &rssi_offset, &lna_2g, lna_5g); caldata->lna_gain = mt76x02_get_lna_gain(&dev->mt76, &lna_2g, lna_5g, chan); -} - -static void -mt76x0_set_rssi_offset(struct mt76x0_dev *dev, u8 *eeprom) -{ - int i; - s8 *rssi_offset = dev->ee->rssi_offset_2ghz; - - for (i = 0; i < 2; i++) { - rssi_offset[i] = eeprom[MT_EE_RSSI_OFFSET_2G_0 + i]; + for (i = 0; i < ARRAY_SIZE(caldata->rssi_offset); i++) { + val = rssi_offset >> (8 * i); + if (val < -10 || val > 10) + val = 0; - if (rssi_offset[i] < -10 || rssi_offset[i] > 10) { - dev_warn(dev->mt76.dev, - "Warning: EEPROM RSSI is invalid %02hhx\n", - rssi_offset[i]); - rssi_offset[i] = 0; - } - } - - rssi_offset = dev->ee->rssi_offset_5ghz; - - for (i = 0; i < 3; i++) { - rssi_offset[i] = eeprom[MT_EE_RSSI_OFFSET_5G_0 + i]; - - if (rssi_offset[i] < -10 || rssi_offset[i] > 10) { - dev_warn(dev->mt76.dev, - "Warning: EEPROM RSSI is invalid %02hhx\n", - rssi_offset[i]); - rssi_offset[i] = 0; - } + caldata->rssi_offset[i] = val; } } @@ -311,7 +288,6 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x0_set_chip_cap(dev, eeprom); mt76x0_set_rf_freq_off(dev, eeprom); mt76x0_set_temp_offset(dev, eeprom); - mt76x0_set_rssi_offset(dev, eeprom); dev->chainmask = 0x0101; mt76x0_set_tx_power_per_rate(dev, eeprom); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index e62c61d91505..dd9cb0d2de41 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -29,14 +29,13 @@ struct reg_channel_bounds { }; struct mt76x0_caldata { + s8 rssi_offset[2]; s8 lna_gain; }; struct mt76x0_eeprom_params { u8 rf_freq_off; s16 temp_off; - s8 rssi_offset_2ghz[2]; - s8 rssi_offset_5ghz[3]; /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ u32 tx_pwr_cfg_2g[5][2]; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 08041ea70a1c..72d0ddc381b9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -229,18 +229,8 @@ mt76x0_bbp_set_ctrlch(struct mt76x0_dev *dev, enum nl80211_chan_width width, int mt76x0_phy_get_rssi(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi) { struct mt76x0_caldata *caldata = &dev->caldata; - s8 rssi_offset; - int val; - if (dev->mt76.chandef.chan->band == NL80211_BAND_2GHZ) { - rssi_offset = dev->ee->rssi_offset_2ghz[0]; - } else { - rssi_offset = dev->ee->rssi_offset_5ghz[0]; - } - - val = rxwi->rssi[0] + rssi_offset - caldata->lna_gain; - - return val; + return rxwi->rssi[0] + caldata->rssi_offset[0] - caldata->lna_gain; } static void mt76x0_vco_cal(struct mt76x0_dev *dev, u8 channel)