From patchwork Thu Sep 20 09:12:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607267 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 E918B6CB for ; Thu, 20 Sep 2018 09:34:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8CE52CDCB for ; Thu, 20 Sep 2018 09:34:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC5972CECD; Thu, 20 Sep 2018 09:34:51 +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 3B7D92CDCB for ; Thu, 20 Sep 2018 09:34:51 +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=5DYueJoM4mzLxB0ymepN63RsLpELNbyJQub5OLOxSgI=; b=cNKlroWU71qxtNnh5Ehqzzpn22 t55sUl37Y2JcZ/ri6/8aOi/XguCBA4nB7/KT6US869dTVef4vAvrmW5H9b3Ir6OpDN1hx1/TRdSC2 3wWR2/gl8Q21aF6lMo9uClkeAw3BeVdw9ba93h1OuYHwo5byguU++yyM3Wd+GVpSSPuFJQ80y99OT Ir8CXcIlCFcU1S0jChC/wqK+bu5knkT8IRmz0aeD5aaycTCecFtEI+h0kDySzBhlHptk/9M5WLcnd HxOoPddM74kcsn6tsXO5VlP/HgTyj1w/DkBkhX6SfMYQ5hiGjmDNAQjYS7t1XV9LX0/qJts1cdMsW R8RNgA6Q==; 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 1g2vM5-0004Cs-Cd; Thu, 20 Sep 2018 09:34:37 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2vE8-0007yC-G6 for linux-mediatek@bombadil.infradead.org; Thu, 20 Sep 2018 09:26:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=qo7k4hwHwFwOYMUvB/PIIoVeigg2yZLY0qQdoaw2f2Y=; b=an5UQw7J0pOYMpC6Hl2H0eClu s19zMY9jmD5cVJBZbHLEOOqPqdpNKmvGxGECoIk+0f8+nW0+jhEiU3Yw5/uMvw6BtSmtMKZcgSwiN YZBCgbvAruZDFxSbdCm8SA7qRYPCKmzpBO09CO8P+B7saOK/Pag3LHat921PAq2wZPPiVWmZWeKMT VktxaAtFbtrwNVKQgqw4P81TGKC4US2N2YArSjwqWr3Q0BJsLRHe1Y0/B/3O7WX9aNuBq0Eb1wbqH lEcB4CSz3UKxoSq1dw58fY6nu9swJwmQYui86u+UHa/jYeW0RV+ekFJ1hvrt0r+nGpzDSpu4w3NfQ nwaeyWLvQ==; Received: from mail-wm1-f67.google.com ([209.85.128.67]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2v0x-0000Wz-R2 for linux-mediatek@lists.infradead.org; Thu, 20 Sep 2018 09:12:48 +0000 Received: by mail-wm1-f67.google.com with SMTP id t25-v6so10014826wmi.3 for ; Thu, 20 Sep 2018 02:12:40 -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=qo7k4hwHwFwOYMUvB/PIIoVeigg2yZLY0qQdoaw2f2Y=; b=IV7L3Dqn6baG3t6osk9gh7ahsOR/3CnIWWYe9nC9yOBAAFFAB7b+KqmeHq6Pwb94Zj Amh/8gcJ0z9SnaT8jcpGK3YG3apw6KLvhnfeA49OSGErnM3SiV/Ft2IebFGoaqhWLNQ5 vQ1bYv6X2Mb5mZpaBGThiA3Yv7gfC9DodtYowiRAgJSJakduZGah3iAwSNssqe31CKcF QWRK2nsCFHVgfGHeAE6F2ItwHewhPmI+kvZc5lt4WpV6WEvp2VMunASCOYR9dsW9Zxkq o+OBhBjtlRt4vgVTeHKcDL/WvamluruIyPqV6jRqu6plU0dIU2U190M8S2CTkxxbrf59 wkDg== X-Gm-Message-State: APzg51BN9bUQvXl4XqDc1vfWZ3SsUucukFd3GC0sdcKF2hByV4YgPGOH DTfGY/4/+ELStTjpy0NnbpvDqQ== X-Google-Smtp-Source: ANB0VdZYURs3f0+5FS/RJTuRsy8bi2mqtsO+U9OCfbtw3Y+I9u+tKaKJS5g1hoNGY6irXXhelUd/1A== X-Received: by 2002:a1c:60d5:: with SMTP id u204-v6mr1603842wmb.88.1537434758655; Thu, 20 Sep 2018 02:12:38 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:38 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Subject: [PATCH 14/20] mt76x0: unify freq offset parsing Date: Thu, 20 Sep 2018 11:12:01 +0200 Message-Id: <3a1d075efd810e114233f941b7b15b3c88955c8f.1537433365.git.lorenzo.bianconi@redhat.com> 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_051247_946145_97BD8D5C X-CRM114-Status: GOOD ( 11.86 ) 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 frequency 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 | 3 ++- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 26 +++++++++---------- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 3 +-- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 3 ++- .../wireless/mediatek/mt76/mt76x02_eeprom.h | 5 ++++ 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index d138ed3bda17..39c2c846f808 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -102,7 +102,8 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) u16 val; int i; - seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off); + 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", diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index ae7c11519b0a..70dd96051e77 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -103,23 +103,21 @@ static void mt76x0_set_temp_offset(struct mt76x0_dev *dev) dev->caldata.temp_offset = -10; } -static void -mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom) +static void mt76x0_set_freq_offset(struct mt76x0_dev *dev) { - u8 comp; + struct mt76x0_caldata *caldata = &dev->caldata; + u8 val; - comp = eeprom[MT_EE_FREQ_OFFSET_COMPENSATION]; - if (!mt76x02_field_valid(comp)) - comp = 0; + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_FREQ_OFFSET); + if (!mt76x02_field_valid(val)) + val = 0; + caldata->freq_offset = val; - dev->ee->rf_freq_off = eeprom[MT_EE_FREQ_OFFSET]; - if (!mt76x02_field_valid(dev->ee->rf_freq_off)) - dev->ee->rf_freq_off = 0; + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TSSI_BOUND4) >> 8; + if (!mt76x02_field_valid(val)) + val = 0; - if (comp & BIT(7)) - dev->ee->rf_freq_off -= comp & 0x7f; - else - dev->ee->rf_freq_off += comp; + caldata->freq_offset -= mt76x02_sign_extend(val, 8); } void mt76x0_read_rx_gain(struct mt76x0_dev *dev) @@ -286,7 +284,7 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR); mt76x0_set_chip_cap(dev, eeprom); - mt76x0_set_rf_freq_off(dev, eeprom); + mt76x0_set_freq_offset(dev); mt76x0_set_temp_offset(dev); dev->chainmask = 0x0101; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index 55e624cf7f2a..8006d08cba45 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -33,11 +33,10 @@ struct mt76x0_caldata { s8 lna_gain; s16 temp_offset; + u8 freq_offset; }; struct mt76x0_eeprom_params { - u8 rf_freq_off; - /* 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]; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index dbe9e2ee5def..c3db4c1cd4fe 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -942,7 +942,8 @@ mt76x0_rf_init(struct mt76x0_dev *dev) E1: B0.R22<6:0>: xo_cxo<6:0> E2: B0.R21<0>: xo_cxo<0>, B0.R22<7:0>: xo_cxo<8:1> */ - rf_wr(dev, MT_RF(0, 22), min_t(u8, dev->ee->rf_freq_off, 0xBF)); + rf_wr(dev, MT_RF(0, 22), + min_t(u8, dev->caldata.freq_offset, 0xbf)); val = rf_rr(dev, MT_RF(0, 22)); /* diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 2132af9f8c94..995aebbcc194 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -74,7 +74,12 @@ enum mt76x02_eeprom_field { MT_EE_2G_TARGET_POWER = 0x0d0, MT_EE_TEMP_OFFSET = 0x0d1, + MT_EE_TSSI_BOUND1 = 0x0d4, + MT_EE_TSSI_BOUND2 = 0x0d6, + MT_EE_TSSI_BOUND3 = 0x0d8, + MT_EE_TSSI_BOUND4 = 0x0da, MT_EE_FREQ_OFFSET_COMPENSATION = 0x0db, + MT_EE_TSSI_BOUND5 = 0x0dc, MT_EE_TX_POWER_BYRATE_BASE = 0x0de, MT_EE_RF_TEMP_COMP_SLOPE_5G = 0x0f2,